Tamil
Tamil

Reputation: 1173

How to generate device specific unique uuid in swift

I want to generate a device specific random uuid which does not change even if the user uninstalls all my apps and reinstall unlike identifierforvendor. How can I achieve this is Swift

Upvotes: 0

Views: 956

Answers (2)

Aashish1aug
Aashish1aug

Reputation: 805

You can use the following function for creating the UUID:

func getUniqueDeviceIdentifierAsString() -> String {
    var appName: String? = (Bundle.main.infoDictionary?[(kCFBundleNameKey as? String)] as? String)
    var strApplicationUUID: String = SSKeychain.password(forService: appName, account: "incoding")
    if strApplicationUUID == nil {
        strApplicationUUID = UIDevice.current.identifierForVendor.uuidString
        SSKeychain.setPassword(strApplicationUUID, forService: appName, account: "incoding")
    }
    return strApplicationUUID
}

reference :How to preserve identifierForVendor in ios after uninstalling ios app on device?

Upvotes: 2

Jasmeet Kaur
Jasmeet Kaur

Reputation: 1568

You need to create random UUID and save it to keychain. Try below link

https://github.com/taka0125/TAKUUID

Upvotes: 0

Related Questions