麦克外部驱动器未被识别为可移动存储

发布于 2024-08-10 13:38:33 字数 252 浏览 11 评论 0原文

我有一个外部 1TB 驱动器,我的程序无法将其识别为可移动存储设备。

我的代码中有以下几行来检测连接到计算机的可移动驱动器。

NSArray *removableDrivesPaths = [[NSWorkspace共享工作空间] MountedRemovableMedia];

请你们告诉我一种方法,让我的外部驱动器被检测为可移动存储设备,或者是否有任何其他可可框架功能可以用来将我的外部驱动器检测为可移动存储设备。

谢谢

I have a external 1TB drive which is not getting recognized by my program as removable storage device.

I have in my code the following lines to detect the removable drives attached to the machine.

NSArray *removableDrivesPaths = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];

Please can you guys tell me a method to get my external drives get detected as removable storage devices or if there is any other cocoa framework function that i can use to detect my external drives as removable storage devices.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泅人 2024-08-17 13:38:33

“可移动”介质是一种物理上与其所在驱动器不同的介质,即软盘或 CD 驱动器。所以不退回外部硬盘是正确的。不过,我不确定您将如何找到您想要的信息。

"Removable" media is one that is physically distinct from the drive it is placed within - i.e. a floppy or a CD drive. So this is correct in not returning external hard drives. I'm not sure how you would go about finding the information you want, though.

情感失落者 2024-08-17 13:38:33

从 OS X 10.7 开始,NSURL API 有两个键 NSURLVolumeIsLocalKeyNSURLVolumeIsInternalKey。外部驱动器应该是本地的,但不是内部的。另外,NSURLVolumeIsInternalKey 必须不为 nil(对于已安装的磁盘映像,它为 nil)。

NSError *error;
NSArray *resourceKeys = @[NSURLVolumeIsLocalKey, NSURLVolumeIsInternalKey];
NSDictionary *valuesDict = [volumeURL resourceValuesForKeys:resourceKeys error:&error];
if (valuesDict != nil) {
    NSNumber *isLocal = valuesDict[NSURLVolumeIsLocalKey];
    NSNumber *isInternal = valuesDict[NSURLVolumeIsInternalKey];
    if (isLocal != nil && isInternal != nil) {
        BOOL isExternal = [isLocal boolValue] && ![isInternal boolValue];
        NSLog(@"Drive external: %d", isExternal);
    }
} else {
    NSLog(@"Error getting resource for volume URL: %@", [error localizedDescription]);
}

Starting from OS X 10.7, NSURL API has two keys NSURLVolumeIsLocalKey and NSURLVolumeIsInternalKey. External drives should be local, but not internal. Also NSURLVolumeIsInternalKey must be not nil (it is nil for mounted disk images).

NSError *error;
NSArray *resourceKeys = @[NSURLVolumeIsLocalKey, NSURLVolumeIsInternalKey];
NSDictionary *valuesDict = [volumeURL resourceValuesForKeys:resourceKeys error:&error];
if (valuesDict != nil) {
    NSNumber *isLocal = valuesDict[NSURLVolumeIsLocalKey];
    NSNumber *isInternal = valuesDict[NSURLVolumeIsInternalKey];
    if (isLocal != nil && isInternal != nil) {
        BOOL isExternal = [isLocal boolValue] && ![isInternal boolValue];
        NSLog(@"Drive external: %d", isExternal);
    }
} else {
    NSLog(@"Error getting resource for volume URL: %@", [error localizedDescription]);
}
尸血腥色 2024-08-17 13:38:33

不确定您要做什么,但如果您只想从设备访问文件,它应该显示为 /Volumes 下的驱动器。

Not sure what you're trying to do, but if you'd just like to access files from the device it should appear as a drive under /Volumes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文