Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique Identifier of a Mac?

On an iPhone I can use

[[UIDevice currentDevice] uniqueIdentifier]; 

to get a string which identifies this device. Is there anything equal in OSX ? I didn't find anything. I just want to identify the Mac which started the application. Can you help me ?

like image 570
Sandro Meier Avatar asked May 03 '11 11:05

Sandro Meier


People also ask

What is unique identifier in computer?

A unique identifier (UID) is a numeric or alphanumeric string that is associated with a single entity within a given system. UIDs make it possible to address that entity, so that it can be accessed and interacted with.

What is Apple UUID?

A universally unique value to identify types, interfaces, and other items. iOS 6.0+ iPadOS 6.0+ macOS 10.8+ Mac Catalyst 13.0+ tvOS 9.0+ watchOS 2.0+ Xcode 8.0+


1 Answers

Apple has a technote on uniquely identifying a mac. Here's a loosely modified version of the code Apple has posted in that technote... don't forget to link your project against IOKit.framework in order to build this:

#import <IOKit/IOKitLib.h>  - (NSString *)serialNumber {     io_service_t    platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,      IOServiceMatching("IOPlatformExpertDevice"));     CFStringRef serialNumberAsCFString = NULL;      if (platformExpert) {         serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert,                                                          CFSTR(kIOPlatformSerialNumberKey),                                                              kCFAllocatorDefault, 0);         IOObjectRelease(platformExpert);     }      NSString *serialNumberAsNSString = nil;     if (serialNumberAsCFString) {         serialNumberAsNSString = [NSString stringWithString:(NSString *)serialNumberAsCFString];         CFRelease(serialNumberAsCFString);     }      return serialNumberAsNSString; } 
like image 152
Jarret Hardie Avatar answered Sep 17 '22 15:09

Jarret Hardie