Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to identify a mounted device as removable?

eemceebeeeemceebee Posts: 28Registered Users
How can I figure out if a mounted device can be unmounted/ejected ?

I tried to get all devices with the help of the NSFileManager.
NSArray *keys = [NSArray arrayWithObjects:NSURLVolumeNameKey, NSURLVolumeURLForRemountingKey, NSURLVolumeIsEjectableKey, NSURLVolumeIsRemovableKey, nil];
NSArray *urls = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:keys options:0];

for (NSURL *url in urls)
NSError *error;
NSNumber *isRemovable;
NSNumber *isEjectable;
NSString *volumeName;

[url getResourceValue:&isEjectable NSURLVolumeIsEjectableKey error:&error];
[url getResourceValue:&isRemovable forKey:NSURLVolumeIsRemovableKey error:&error];
[url getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&error];

NSLog(@Standard Device : %@ - Removable: %@ - Ejectable: %@", volumeName, [isRemovable boolValue] ? @yes : @no,[isEjectable boolValue] ? @yes : @no);
But when I iterate through the list, I always get this e.g.:

Standard Device Name: My Book - Removable: - isEjectable:
FYI, "My Book" is a USB drive.

I hope someone can point out what is wrong.

Sign In or Register to comment.