题
我发现使用IOServiceGetMatchingServices
我的设备,并获得属性字典是这样的:
kernResult = IORegistryEntryCreateCFProperties(nextMedia,
(CFMutableDictionaryRef *)&props,
kCFAllocatorDefault, 0);
从该字典我可以提取信息的图标:
NSString *bId = [props valueForKeyPath:@"IOMediaIcon.CFBundleIdentifier"];
NSString *rFile = [props valueForKeyPath:@"IOMediaIcon.IOBundleResourceFile"];
这两个给我这个(作为一个例子):
com.apple.iokit.IOStorageFamily (Bundle identifier) Internal.icns (Resource File)
我试图使用这种方法提取图标:
NSBundle *bundleWithIcon = [NSBundle bundleWithIdentifier:bId];
NSString *iconPath = [bundleWithIcon pathForResource:rFile ofType:nil];
但是bundleWithIcon
是nil
。
这甚至让图标正确的方法?的
我觉得我必须以某种方式加载包能够与bundleWithIdentifier
加载它,我该怎么办呢?
PS:有这(我认为)试图询问同样的事情,另外一个问题,但是只要求束,而不是如果这是正确的方法。
解决方案 2
就在最近安德鲁·迈里克回答过类似的问题一>达尔文-dev邮件列表上:
KextManagerCreateURLForBundleIdentifier()
在<IOKit/kext/KextManager.h>
可能 使用的,但我相信这只是工作 对于要么1)加载kext文件, 或2)/ S / L / E /。这里是雪 豹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's 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);
请注意之前雪豹,它 可以仅对于在/ S / L / E kext文件工作;该 API存在,但没有 headerdoc描述它的行为。
对于我这样的工作非常出色在Mac OS X 10.5。
其他提示
您可以使用NSWorkspace。结果 初始图像是32×32,但它具有表示为其它尺寸,并相应地缩放
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
NSImage * icon = [ws iconForFile:@"/Volumes/Whatever"];
NSLog(@"%@", [icon representations]); // see what sizes the icon has
icon.size = NSMakeSize(512, 512);
这可以帮助你。 (或者不)...
在玩弄了“名为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”,这本身似乎是一个集合,告知您捆绑标识符和资源文件的名称。
不是说这很容易......但看看到火线SDK 的所有你可能需要的示例代码... 在任何情况下,它比硬编码预填充路径(这可能会在未来的OS版本中消失)。
可能是“更好”| K <
这两个给我这个(作为一个例子):
com.apple.iokit.IOStorageFamily(包标识符) Internal.icns(资源文件)
我试图使用这种方法提取图标:
一个NSBundle * bundleWithIcon = [一个NSBundle bundleWithIdentifier:出价]; 的NSString * iconPath = [bundleWithIcon pathForResource:的RFile ofType:无];
但是
bundleWithIcon
是nil
。
bundleWithIdentifier:
需要你已经创造了一个一个NSBundle实例与该标识符的包;它只是查找先前创建的实例。因此,你需要找到在文件系统中的包,并通过路径实例化。幸运的是,你似乎已经拥有的链接有关的问题。
没有自定义图标的卷是要与操作系统的通用图标一个您已硬编码路径在这里显示。使用自定义图标卷是去那个图标存储在它的文件系统,如果它不安装,发现它完全变成你的工作。