Generating a computer-specific UUID in Xcode
How do I generate a UUID that will uniquely identify a computer using Xcode / Objective-C? Windows has UuidCreateSequential()
, what can I use on开发者_StackOverflow中文版 a Mac?
Try this:
CFUUIDRef UUID = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef UUIDString = CFUUIDCreateString(kCFAllocatorDefault,UUID);
// UUIDString is the CFStringRef (== NSString *) that contains the UUID.
// Cleanup
CFRelease(UUID);
CFRelease(UUIDString);
You can read the system serial number or the hardware MAC addresses using IOKit.
Check out Apple Technical Note TN1103 ("Uniquely Identifying a Macintosh Computer") for sample code and more information.
[[NSProcessInfo processInfo] globallyUniqueString];
精彩评论