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;
NSString *volumeName;
[url getResourceValue:&isRemovable forKey:NSURLVolumeIsRemovableKey error:&error];
[url getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&error];
NSLog(@"Standard Device : %@ - Removable: %c", volumeName, [isRemovable boolValue]);
}
But when I iterate through the list, I always get this e.g.:
Standard Device Name: My Book - isEjectable:
FYI, "My Book" is a USB drive.
I hope someone can point out what is wrong.
Thanks
You want the NSURLVolumeIsEjectableKey not NSURLVolumeIsRemovableKey.
NSURLVolumeIsRemovableKey means the media can be physically removed from the device. NSURLVolumeIsEjectableKey indicates that the volume can be unmounted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With