Search code examples
iosmacoscocoaosx-lion

UIDevice class for Mac OS X?


I am trying to port one of my iOS applications to Mac OS X, and I am struggling to find the UIDevice-like object for OS X. I am interested in getting the name of the device, such as "MacBookAir".

EDIT/ANSWER
As Josh Caswell pointed out, you can use SCDynamicStoreCopyComputerName key.

Here is the code:

+ (NSString *)computerName {
   return [(id)SCDynamicStoreCopyComputerName(NULL, NULL) autorelease];
}

Solution

  • The Net Services Programming Guide says:

    In Mac OS X on the desktop, calling the SCDynamicStore function from the System Configuration framework returns the computer name so you can manipulate it like any other string. In iOS, you can obtain the same information from the name property of the UIDevice class.

    There doesn't seem to be a single function called SCDynamicStore (doc bug), but you probably want SCDynamicStoreCopyValue. Looks like you get the key you need using SCDynamicStoreKeyCreateComputerName.

    EDIT: Or, even better, as you found, use the SCDynamicStoreCopyComputerName function, found in SCDynamicStoreCopySpecific.h