Device UUID not unique when user uninstall and re-install

后端 未结 2 1011
长发绾君心
长发绾君心 2021-01-03 10:39

I have a system where each user allowed to install apps for two devices only. The issue is happened when user uninstall and reinstall again on the same device. So it will ge

相关标签:
2条回答
  • 2021-01-03 11:01

    This is the expected bevaiour. If you want to use same UUID you need to save it to the keyChain. I have done something simmiler in of my apps using KeyChainWrapper

    So here is a sample chunk for you

    let deviceId = UIDevice.currentDevice().identifierForVendor?.UUIDString ?? ""
    // Saving Id in keyChain
    KeychainWrapper.defaultKeychainWrapper().setString(deviceId, forKey: "CurrentDeviceId")
    

    And then just get Id from keyChain everytime you want to use it.

    let previousDeviceId = KeychainWrapper.defaultKeychainWrapper().stringForKey("CurrentDeviceId")
    
    0 讨论(0)
  • 2021-01-03 11:07

    You need to use keychain: (to be able to imort JNKeychain you need to enter a new string in your pod file pod 'JNKeychain'). This will guaranty you that if you don't change you bundle identifier, you will always have a uniq device id (that will stay the same even after deleting your app). I used that when user was banned forever in our application, he couldn't enter the app even with different account even after deleting the app.

    import UIKit
    import JNKeychain
    
    class KeychainManager: NSObject {
        static let sharedInstance = KeychainManager()
    
        func getDeviceIdentifierFromKeychain() -> String {
    
            // try to get value from keychain
            var deviceUDID = self.keychain_valueForKey("keychainDeviceUDID") as? String
            if deviceUDID == nil {
                deviceUDID = UIDevice.current.identifierForVendor!.uuidString
                // save new value in keychain
                self.keychain_setObject(deviceUDID! as AnyObject, forKey: "keychainDeviceUDID")
            }
            return deviceUDID!
        }
    
        // MARK: - Keychain
    
        func keychain_setObject(_ object: AnyObject, forKey: String) {
            let result = JNKeychain.saveValue(object, forKey: forKey)
            if !result {
                print("keychain saving: smth went wrong")
            }
        }
    
        func keychain_deleteObjectForKey(_ key: String) -> Bool {
            let result = JNKeychain.deleteValue(forKey: key)
            return result
        }
    
        func keychain_valueForKey(_ key: String) -> AnyObject? {
            let value = JNKeychain.loadValue(forKey: key)
            return value as AnyObject?
        }
    }
    
    0 讨论(0)
提交回复
热议问题