Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get UDID of iPhone? [duplicate]

Tags:

ios

iphone

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)")

like image 525
sagar varsani Avatar asked Feb 27 '16 09:02

sagar varsani


4 Answers

Swift 3.X Latest simple usage;

if let identifierForVendor = UIDevice.current.identifierForVendor {
    print(identifierForVendor.uuidString)
}
like image 90
SwiftDeveloper Avatar answered Oct 11 '22 17:10

SwiftDeveloper


This is working in swift 3 / Xcode / Iphone7 for me.

let deviceUUID: String = (UIDevice.current.identifierForVendor?.uuidString)!
like image 37
thexande Avatar answered Oct 11 '22 16:10

thexande


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

like image 22
Avinash651 Avatar answered Oct 11 '22 16:10

Avinash651


Try this ,

UIDevice.currentDevice().identifierForVendor

or if you want a string:

UIDevice.currentDevice().identifierForVendor.UUIDString
print(UIDevice.currentDevice().identifierForVendor().UUIDString()) //Print Log
like image 6
Badal Shah Avatar answered Oct 11 '22 17:10

Badal Shah