To save the UUID we can use SSKeychainUtility. Example can be found on Github page
func randomUUID() -> NSString{
return NSUUID.UUID().UUIDString()
}
+ (NSString *)randomUUID {
if(NSClassFromString(@"NSUUID")) { // only available in iOS >= 6.0
return [[NSUUID UUID] UUIDString];
}
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef cfuuid = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
CFRelease(uuidRef);
NSString *uuid = [((__bridge NSString *) cfuuid) copy];
CFRelease(cfuuid);
return uuid;
}
Within a single line, we can get an UUID like below:
let UDIDString = UIDevice.currentDevice().identifierForVendor?.UUIDString
NSString *UDIDString = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
The identifierForVendor
is an unique identifier that stays the same for every app of a single vendor on a single device, unless all of the vendor's apps are deleted from this device. See Apple's documentation about when this UUID
changes.
advertisingIdentifier: UUID: An alphanumeric string unique to each device, used only for serving advertisements.
isAdvertisingTrackingEnabled: A Boolean value that indicates whether the user has limited ad tracking.
Find your device IFA and IFV here.
Here we can create UUID String
with in one line.
Represents UUID strings, which can be used to uniquely identify types, interfaces, and other items.
print(UUID().uuidString)
It is very useful for identify multiple devices with unique id.