简体   繁体   中英

How to get device phone number or unique id in Swift?

Is there anyway how can I detect device its phone number with Swift? It's because I want to get unique id of iOS device number for my app. In android, we can get device's secure id and its id never change whenever app is uninstalled and install again. For Swift, how can I get unique id or phone number then?

android unique id as well as secure id example

String deviceId = Secure.getString(this.getContentResolver(),
            Secure.ANDROID_ID);

iOS Swift

var uuid = NSUUID().UUIDString

Above line uuide will be change after re-installing app?

Apple had to remove access to the device's UUID after a major privacy kerfuffle in the media.

Now there is a UIDevice call identifierForVendor that gets you pretty close. It's an ID that is unique for the current device from your app.

Here is a piece of code

    let dID = CFUUIDCreate(kCFAllocatorDefault)
    let deviceID = CFUUIDCreateString(kCFAllocatorDefault, deviceID) as NSString

In swift 3.1 can use

if let support =  NSClassFromString("FTDeviceSupport")?.value(forKey: "sharedInstance") as? NSObject  {

       support.value(forKey: "telephoneNumber")!



    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM