我需要在我的应用程序中获取图形卡信息.我需要的信息与*system_profiler SPDisplays*命令在Graphics/Displays:部分下显示的信息相同.我已经考虑过使用sysctl(),但是我无法在sysctl.h中找到适合图形卡的硬件选择器
任何建议都高度重视.
在摆弄IOKit之后,我设法获取了所需的信息.代码可以在这里看到(原始来源)和下面:
- (void)displayGraphicsInfo
{
// Get dictionary of all the PCI Devicces
CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");
// Create an iterator
io_iterator_t iterator;
if (IOServiceGetMatchingServices(kIOMasterPortDefault,matchDict,
&iterator) == kIOReturnSuccess)
{
// Iterator for devices found
io_registry_entry_t regEntry;
while ((regEntry = IOIteratorNext(iterator))) {
// Put this services object into a dictionary object.
CFMutableDictionaryRef serviceDictionary;
if (IORegistryEntryCreateCFProperties(regEntry,
&serviceDictionary,
kCFAllocatorDefault,
kNilOptions) != kIOReturnSuccess)
{
// Service dictionary creation failed.
IOObjectRelease(regEntry);
continue;
}
const void *GPUModel = CFDictionaryGetValue(serviceDictionary, @"model");
if (GPUModel != nil) {
if (CFGetTypeID(GPUModel) == CFDataGetTypeID()) {
// Create a string from the CFDataRef.
NSString *modelName = [[NSString alloc] initWithData:
(NSData *)GPUModel encoding:NSASCIIStringEncoding];
NSLog(@"GPU Model: %@", modelName);
[modelName release];
}
}
// Release the dictionary
CFRelease(serviceDictionary);
// Release the serviceObject
IOObjectRelease(regEntry);
}
// Release the iterator
IOObjectRelease(iterator);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1651 次 |
| 最近记录: |