• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting Display Names
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting Display Names


  • Subject: Re: Getting Display Names
  • From: Cédric Luthi <email@hidden>
  • Date: Tue, 28 Apr 2009 14:40:39 +0200

> Are these names only accessible from private frameworks or is there an
> AppKit or CoreGraphics API I have yet to stumble across that maps the
> display unit number or display ID to a localized (or not) display name?

The answer is in I/O Kit:


#import <IOKit/graphics/IOGraphicsLib.h>

#import <IOKit/graphics/IOGraphicsTypes.h>

NSString* screenNameForDisplayID(CGDirectDisplayID displayID)

{

    NSDictionary *deviceFullDescription = (NSDictionary *)
IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kNilOptions
);

    if (deviceFullDescription == nil) {

        return nil;

    }



    NSDictionary *localizedNames = [deviceFullDescription objectForKey
:@kDisplayProductName];

    if ([localizedNames count] < 1) {

        return nil;

    }



    NSString *languageKey = nil;

    for (NSString *preferredLanguage in [NSLocale preferredLanguages]) {

        for (NSString *localeIdentifier in [localizedNames allKeys]) {

            if ([[[NSLocale componentsFromLocaleIdentifier
:preferredLanguage] objectForKey:NSLocaleLanguageCode] isEqualToString:[[
NSLocale componentsFromLocaleIdentifier:localeIdentifier] objectForKey:
NSLocaleLanguageCode]]) {

                languageKey = localeIdentifier;

                goto exit;

            }

        }

    }

    exit:



    return [localizedNames objectForKey:languageKey ? languageKey :
[[localizedNames allKeys] objectAtIndex:0]];

}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Getting Display Names (From: Grant Erickson <email@hidden>)

  • Prev by Date: Cookie accept policy
  • Next by Date: Bindings confusion
  • Previous by thread: Getting Display Names
  • Next by thread: Re: Getting Display Names
  • Index(es):
    • Date
    • Thread