UIDevice uniqueIdentifier deprecated - What to do now?

后端 未结 30 2154
日久生厌
日久生厌 2020-11-21 06:07

It has just come to light that the UIDevice uniqueIdentifier property is deprecated in iOS 5 and unavailable in iOS 7 and above. No alternative method or pr

30条回答
  •  孤独总比滥情好
    2020-11-21 06:32

    A not perfect but one of the best and closest alternative to UDID (in Swift using iOS 8.1 and Xcode 6.1):

    Generating a random UUID

    let strUUID: String = NSUUID().UUIDString
    

    And use KeychainWrapper library:

    Add a string value to keychain:

    let saveSuccessful: Bool = KeychainWrapper.setString("Some String", forKey: "myKey")
    

    Retrieve a string value from keychain:

    let retrievedString: String? = KeychainWrapper.stringForKey("myKey")
    

    Remove a string value from keychain:

    let removeSuccessful: Bool = KeychainWrapper.removeObjectForKey("myKey")
    

    This solution uses the keychain, thus the record stored in the keychain will be persisted, even after the app is uninstalled and reinstalled. The only way of deleting this record is to Reset all contents and settings of the device. That is why I mentioned that this solution of substitution is not perfect but stays one of the best solution of replacement for UDID on iOS 8.1 using Swift.

提交回复
热议问题