Mac + External drive not recognized as removable storage
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
"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.
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]);
}
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.
精彩评论