简体   繁体   English

如何在Swift中获取设备电话号码或唯一ID?

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

Is there anyway how can I detect device its phone number with Swift? 无论如何,我怎么能用Swift检测设备的电话号码? It's because I want to get unique id of iOS device number for my app. 这是因为我想为我的应用获取iOS设备号的唯一ID。 In android, we can get device's secure id and its id never change whenever app is uninstalled and install again. 在android中,我们可以获得设备的安全ID,并且只要卸载并重新安装应用程序,其ID就不会更改。 For Swift, how can I get unique id or phone number then? 对于Swift,我怎样才能获得唯一的ID或电话号码呢?

android unique id as well as secure id example android唯一ID以及安全id示例

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

iOS Swift iOS Swift

var uuid = NSUUID().UUIDString

Above line uuide will be change after re-installing app? 重新安装应用程序后,上面的uuide会有变化吗?

Apple had to remove access to the device's UUID after a major privacy kerfuffle in the media. 在媒体发生重大隐私骚乱后,Apple不得不取消对该设备UUID的访问权限。

Now there is a UIDevice call identifierForVendor that gets you pretty close. 现在有一个UIDevice调用identifierForVendor让你非常接近。 It's an ID that is unique for the current device from your app. 它是您应用中当前设备唯一的ID。

Here is a piece of code 这是一段代码

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

In swift 3.1 can use 在swift 3.1中可以使用

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

       support.value(forKey: "telephoneNumber")!



    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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