Mac + External drive not recognized as removable storage

1.6k views Asked by At

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

3

There are 3 answers

1
Benjamin Cox On

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.

0
Steven Schlansker On

"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.

0
eofster On

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]);
}