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
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")
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?
}
}