【问题标题】:Getting graphic card information in objective C在Objective C中获取显卡信息
【发布时间】:2015-11-13 16:21:08
【问题描述】:

我需要在我的应用程序中获取显卡信息。我需要的信息与 Graphics/Displays: 部分下的 *system_profiler SPDisplays* 命令显示的信息相同。 我已经考虑过使用 sysctl(),但我无法在 sysctl.h 中找到适合显卡的硬件选择器

任何建议都非常受欢迎。

【问题讨论】:

标签: objective-c macos


【解决方案1】:

在摆弄 IOKit 之后,我设法获取了所需的信息。代码可见here(original source)及以下:

- (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);
    }
}

【讨论】:

  • 请包含您网站上的代码,目前该代码已关闭。 (另见Your answer is in another castle: when is an answer not an answer?)。
  • 你好@rsharma!我已为您的答案提交了一个版本,以包含该链接中的代码,这样即使网站被所有者关闭,您的答案仍然有效。
  • 是的,这段代码看起来像是来自here,没有署名。
  • @trojanfoe 是的,可能是。这是我创建的旧帖子,我可能错过了参考来源。我会马上做(并且在答案上)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多