CGDisplayIOServicePort is deprecated in OS X >= 10.9, how to replace?

后端 未结 3 2075
不知归路
不知归路 2021-02-07 10:14

I did small app to allow quickly change screen resolutions on multiple monitors. I want to show product name as title of the monitor, and it\'s very simple to find using this co

3条回答
  •  长情又很酷
    2021-02-07 10:42

    NSString* screenNameForDisplay(CGDirectDisplayID displayID)
    {
        NSString *screenName = nil;
        io_service_t service = IOServicePortFromCGDisplayID(displayID);
        if (service)
        {
            NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(service, kIODisplayOnlyPreferredName);
            NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
    
            if ([localizedNames count] > 0) {
                screenName = [[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] retain];
            }
    
            [deviceInfo release];
        }
        return [screenName autorelease];
    }
    

提交回复
热议问题