I've found my devices using IOServiceGetMatchingServices
and got the property dictionary like this:
kernResult = IORegistryEntryCreateCFProperties(nextMedia,
(CFMutableDictionaryRef *)&props,
kCFAllocatorDefault, 0);
From that dictionary I can extract the informations for the icons:
NSString *bId = [props valueForKeyPath:@"IOMediaIcon.CFBundleIdentifier"];
NSString *rFile = [props valueForKeyPath:@"IOMediaIcon.IOBundleResourceFile"];
Those two give me this (as an example):
com.apple.iokit.IOStorageFamily (Bundle identifier) Internal.icns (Resource File)
I tried to extract the icon using this method:
NSBundle *bundleWithIcon = [NSBundle bundleWithIdentifier:bId];
NSString *iconPath = [bundleWithIcon pathForResource:rFile ofType:nil];
But bundleWithIcon
is nil
.
Is this even the correct method to get the icon?
I think I have to somehow load the bundle to be able to load it with bundleWithIdentifier
, how can I do this?
PS: There's another question which (I think) tries to ask the same thing, but only asks for bundles, not if this is the correct way.