Objective c 在objective C中获取图形卡信息
我需要在我的应用程序中获取图形卡信息。我需要的信息与图形/显示部分下的命令显示的信息相同。 我已经考虑过使用sysctl(),但在sysctl.h中找不到合适的图形卡硬件选择器Objective c 在objective C中获取图形卡信息,objective-c,macos,Objective C,Macos,我需要在我的应用程序中获取图形卡信息。我需要的信息与图形/显示部分下的命令显示的信息相同。 我已经考虑过使用sysctl(),但在sysctl.h中找不到合适的图形卡硬件选择器 任何建议都被高度重视。在摆弄IOKit之后,我设法获取了所需的信息。代码可以在()和下面看到: - (void)displayGraphicsInfo { // Get dictionary of all the PCI Devicces CFMutableDictionaryRef matchDict
任何建议都被高度重视。在摆弄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);
}
}
您应该使用IOKit而不是sysctl:谢谢@Macmade的建议。我将立即从IOKit开始。请包括您网站上的代码,目前该网站已关闭。(另请参见)。你好@rsharma!我已向您的答案提交了一个版本,以包含该链接中的代码,这样即使网站被所有者关闭,您的答案仍然有效。是的,此代码看起来像来自无属性的源代码。@trojanfoe可能是。这是我写的一篇老文章,我可能没有提到来源。我会马上去做(还有答案)。