我正在使用IOKit获取一些信息
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceNameMatching("AppleUSBEHCI"), &io_objects);
[snip]
kr = IORegistryEntryCreateCFProperties(child, &child_props, kCFAllocatorDefault, kNilOptions );
NSLog(@"Child props: %@", child_props);
//release child_props
}
IOObjectRelease(io_service);
}
sn = (CFStringRef) CFDictionaryGetValue(child_props, CFSTR("IOCFPlugInTypes"));
NSLog(@"sn: %@", sn);
我正在使用密钥IOCFPlugInTypes
:
它有效,我回来了:
{
"9dc7b780-9ec0-11d4-a54f-000a27052861" = "IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle";
}
但我接下来需要做的就是获得说:9dc7b780-9ec0-11d4-a54f-000a27052861
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:1)
这里CFDictionaryGetValue返回另一个CFDictionaryRef类型的对象(在你输入的时候不是字符串)。所以“9dc7b780-9ec0-11d4-a54f-000a27052861”是该词典的关键。你应该做以下的事情:
CFTypeRef sn = (CFTypeRef)CFDictionaryGetValue(child_props, CFSTR("IOCFPlugInTypes"));
if (CFDictionaryGetTypeID() == CFGetTypeID(sn))
{
int dictSize = CFDictionaryGetCount(sn);
CFStringRef * keys = (CFStringRef*)malloc (dictSize * sizeof (CFStringRef));
CFDictionaryGetKeysAndValues (sn, keys, NULL);
for (int i = 0; i < dictSize; i++)
{
CFShow(keys[i]);
}
}