Created
March 20, 2014 22:18
-
-
Save calebjohnston/9675166 to your computer and use it in GitHub Desktop.
Creates NSString representation of the serial number for an OSX computer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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