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