I want unique device ID for iPhone that remains unchanged?, I want Unique device ID that cannot be changed if I uninstall application and install again on same device. I am Using swift 2.1.1 and xcode 7.2.1. I have tried this code but both will not work.
//First approach
let device_id = UIDevice.currentDevice().identifierForVendor!.UUIDString
print("unique device id: (device_id)")
//Second approach
let dID = CFUUIDCreate(kCFAllocatorDefault)
let deviceID = CFUUIDCreateString(kCFAllocatorDefault, dID) as NSString
print("unique CFUUID id: (deviceID)")
Swift 3.X Latest simple usage;
if let identifierForVendor = UIDevice.current.identifierForVendor {
print(identifierForVendor.uuidString)
}
This is working in swift 3 / Xcode / Iphone7 for me.
let deviceUUID: String = (UIDevice.current.identifierForVendor?.uuidString)!
Use this
let UUID = CFUUIDCreateString(nil, CFUUIDCreate(nil))
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
let userDefaults = NSUserDefaults.standardUserDefaults()
if userDefaults.objectForKey("ApplicationUniqueIdentifier") == nil {
let UUID = NSUUID.UUID().UUIDString
userDefaults.setObject(UUID, forKey: "ApplicationUniqueIdentifier")
userDefaults.synchronize()
}
return true
}
This will work correctly in swift
Try this ,
UIDevice.currentDevice().identifierForVendor
or if you want a string:
UIDevice.currentDevice().identifierForVendor.UUIDString
print(UIDevice.currentDevice().identifierForVendor().UUIDString()) //Print Log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With