Skip to content

Instantly share code, notes, and snippets.

@calebjohnston
Created March 20, 2014 22:18
Show Gist options
  • Save calebjohnston/9675166 to your computer and use it in GitHub Desktop.
Save calebjohnston/9675166 to your computer and use it in GitHub Desktop.
Creates NSString representation of the serial number for an OSX computer
#import <IOKit/IOKitLib.h>
//
// Creates NSString representation of machine serial number
//
NSString *serial = nil;
io_service_t platform = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
if (platform) {
CFTypeRef serialNumberAsCFString =
IORegistryEntryCreateCFProperty(platform, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0);
if (serialNumberAsCFString) {
serial = CFBridgingRelease(serialNumberAsCFString);
}
IOObjectRelease(platform);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment