从同一个iPhone获取两个不同的设备ID [英] Getting two different device IDs from same iphone

查看:454
本文介绍了从同一个iPhone获取两个不同的设备ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我得到它时,我的iphone会得到不同的UDID 来自itunes 并以编程方式像这样

I am getting different UDIDs for my iphone when i get it from itunes and programatically like this

UDID:String = UIDevice.current.identifierForVendor!.uuidString

基本上我试图获取我的iphone的唯一标识符,就像我们有Android手机的mac地址一样。

Basically im trying to acquire a unique identifier for my iphone just like we have mac address for android phones.

推荐答案

最简单的方法是通过在keychain中存储identifierForVendor来解决这个问题。即使您卸载了应用程序,该键的值仍保持不变且未更改。许多第三方库可以执行此操作。其中一个 https://github.com/jrendel/SwiftKeychainWrapper

one easiest way is to solve this issue by storing the identifierForVendor in keychain. even if you uninstall app ,value for the key remains same and its unchanged. many third party libraries available to perform this . one of them https://github.com/jrendel/SwiftKeychainWrapper.

func getGlobalUniqueIdentifierFromKeyChain()->String{

    let retrievedString: String? = KeychainWrapper.standard.string(forKey: "DeviceId")

    if  retrievedString == nil{
        if let deviceKey  = UIDevice.current.identifierForVendor?.uuidString{
            let _ = KeychainWrapper.standard.set(deviceKey, forKey: "DeviceId")
        }
    }

    if let globalID = KeychainWrapper.standard.string(forKey: "DeviceId"){
        return globalID
    }else{
        return UIDevice.current.identifierForVendor?.uuidString ?? ""
    }
}

这篇关于从同一个iPhone获取两个不同的设备ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆