UIApplication, UIDevice , ( ARC)
@interface UIApplication (utilities)
- (NSString*)getUUID;
@end
@implementation UIApplication (utilities)
- (NSString*)getUUID {
NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];
static NSString *uuid = nil;
if (uuid == nil) {
uuid = [standardUserDefault objectForKey:@"UniversalUniqueIdentifier"];
}
if (uuid == nil) {
uuid = UUID ();
[standardUserDefault setObject:uuid forKey:@"UniversalUniqueIdentifier"];
[standardUserDefault synchronize];
}
return uuid;
}
@end
UUID() -
NSString* UUID () {
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return (__bridge NSString *)uuidStringRef;
}
this generates a unique identifier stored in NSUserDefault for reuse whenever necessary for the application. This identifier will be unique, associated with installing the application not on the device, but can be used, for example, to track the number of devices signed by APN, etc.
After that, you can use it as follows:
NSString *uuid = [[UIApplication sharedApplication] getUUID];
source
share