Pyae Phyoe Shein
Pyae Phyoe Shein

Reputation: 13827

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?

Upvotes: 4

Views: 5369

Answers (3)

Carlos Chaguendo
Carlos Chaguendo

Reputation: 3085

In swift 3.1 can use

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

       support.value(forKey: "telephoneNumber")!



    }

Upvotes: 0

Duncan C
Duncan C

Reputation: 131418

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.

Upvotes: 5

Amit89
Amit89

Reputation: 3000

Here is a piece of code

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

Upvotes: 2

Related Questions