How can I get the icon for a storage device in Mac OS X?

I found my devices using IOServiceGetMatchingServicesand got a property dictionary as follows:

kernResult = IORegistryEntryCreateCFProperties(nextMedia,
                    (CFMutableDictionaryRef *)&props,
                                              kCFAllocatorDefault, 0);

From this dictionary I can extract information for the icons:

NSString *bId = [props valueForKeyPath:@"IOMediaIcon.CFBundleIdentifier"];
NSString *rFile = [props valueForKeyPath:@"IOMediaIcon.IOBundleResourceFile"];

These 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 bundleWithIconthere is nil.

Is this even the right method to get the badge?

I think I need to download the package somehow in order to download it using bundleWithIdentifier, how can I do this?

PS: Another question that (I think) is trying to ask the same thing, but only asks about the bundles, and not if this is the right way.

+3
5

Andrew Myrick darwin-dev:

KextManagerCreateURLForBundleIdentifier() <IOKit/kext/KextManager.h> , , kexts, 1) , 2) /S/L/E/. Leopard headerdoc:

/*!
 * @function KextManagerCreateURLForBundleIdentifier
 * @abstract Create a URL locating a kext with a given bundle identifier.
 *
 * @param    allocator
 *           The allocator to use to allocate memory for the new object.
 *           Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
 *           to use the current default allocator.
 * @param    kextIdentifier
 *           The bundle identifier to look up.
 *
 * @result
 * A CFURLRef locating a kext with the requested bundle identifier.
 * Returns <code>NULL</code> if the kext cannot be found, or on error.
 *
 * @discussion
 * Kexts are looked up first by whether they are loaded, second by version.
 * Specifically, if <code>kextIdentifier</code> identifies a kext
 * that is currently loaded,
 * the returned URL will locate that kext if it still present on disk.
 * If the requested kext is not loaded,
 * or if its bundle is not at the location it was originally loaded from,
 * the returned URL will locate the latest version of the desired kext,
 * if one can be found within the system extensions folder.
 * If no version of the kext can be found, <code>NULL</code> is returned.
 */
CFURLRef KextManagerCreateURLForBundleIdentifier(
    CFAllocatorRef allocator,
    CFStringRef    kextIdentifier);

, Snow Leopard kexts /S/L/E; API , headerdoc, .

Mac OS X 10.5.

+2

NSWorkspace.
32x32, .

NSWorkspace * ws = [NSWorkspace sharedWorkspace];
NSImage * icon = [ws iconForFile:@"/Volumes/Whatever"];
NSLog(@"%@", [icon representations]); // see what sizes the icon has
icon.size = NSMakeSize(512, 512);
+7

. (, , )...

"ioreg", , , :

:

ioreg -c IOMedia -x

, :

  |     +-o IOBlockStorageDriver  <class IOBlockStorageDriver, registered, matched, active, busy 0, retain 7>
  |       +-o Apple read/write Media  <class IOMedia, registered, matched, active, busy 0, retain 9>
  |         | {
  |         |   "Removable" = Yes
  |         |   "BSD Unit" = 0x4
  |         |   "IOBusyInterest" = "IOCommand is not serializable"
  |         |   "BSD Minor" = 0xc
  |         |   "Ejectable" = Yes
  |   |         |   "BSD Name" = "disk4"
  |         |   "Leaf" = No
  |         |   "IOMediaIcon" = {"CFBundleIdentifier"="com.apple.iokit.IOStorageFamily","IOBundleResourceFile"="Removable.icns"}
  |         |   "Preferred Block Size" = 0x200
  |         |   "Whole" = Yes
  |         |   "Open" = Yes
  |         |   "Size" = 0x100000
  |         |   "Writable" = Yes
  |         |   "Content" = "Apple_partition_scheme"
  |         |   "IOGeneralInterest" = "IOCommand is not serializable"
  |         |   "Content Hint" = ""
  |         | }         |   "BSD Major" = 0xe

(, , ), io, "IOMedia", , "IOMediaIcon", , .

, ... FireWire SDK , ... , , "", ( ).

| <

+1

( ):

com.apple.iokit.IOStorageFamily( )   Internal.icns( )

, :

NSBundle * bundleWithIcon = [NSBundle bundleWithIdentifier: bId];   NSString * iconPath = [bundleWithIcon pathForResource: rFile ofType: nil];

bundleWithIcon nil.

bundleWithIdentifier: , NSBundle ; . . , , , .

0

, . , , .

0

Source: https://habr.com/ru/post/1703706/


All Articles