# UUID (Universally Unique Identifier)
# Apple's IFA vs. IFV (Apple Identifier for Advertisers vs. Identifier for Vendors)
- **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.
- ASIdentifierManager class provides
-
- **identifierForVendor: UUID**: An alphanumeric string that uniquely identifies a device to the app’s vendor.
Find your device IFA and IFV here (opens new window).
# Generating UUID
# Random UUID
# Swift
func randomUUID() -> NSString{ return NSUUID.UUID().UUIDString() }
# Objective-C
+ (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; }
# Identifier for vendor
Within a single line, we can get an UUID like below:
# Swift
let UDIDString = UIDevice.currentDevice().identifierForVendor?.UUIDString
# Objective-C
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 (opens new window) about when thisUUID
changes.# Create UUID String for iOS devices
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.
# Swift 3.0
print(UUID().uuidString)
It is very useful for identify multiple devices with unique id.
# Remarks
To save the UUID we can use SSKeychainUtility (opens new window). Example can be found on Github page
← WKWebView Categories →