Reputation: 3653
My app has connected to remote push notification service. In server side they want to keep a unique ID for the device and it should not change even the app has deleted and re installed. Can we get Device UDID and send to the server? And If I did it will Apple reject my app from the store? And I think that is the best ID to keep permanantly in the server side even the app deleted.?
I need your suggestions. Please help me. Thanks
Upvotes: 1
Views: 3641
Reputation: 821
As its mentioned ; When app is installed its uuid is unique but if app deleted and installed again its uuid changes.
So overcome this issue I used Keychain Access to retrieval and saving uuid.
For keychain access wrapper i used a third party named
pod 'SwiftKeychainWrapper'
and for getting uuid I created this method.
func getUDIDofDevice() -> String {
//Check is uuid present in keychain or not
if let deviceId: String = KeychainWrapper.standard.string(forKey: "deviceId") {
return deviceId
}else{
// if uuid is not present then get it and store it into keychain
let key : String = (UIDevice.current.identifierForVendor?.uuidString)!
let saveSuccessful: Bool = KeychainWrapper.standard.set(key, forKey: "deviceId")
print("Save was successful: \(saveSuccessful)")
return key
}
}
What will happen here : if in keychain access uuid is not present then by using uuid string save it. and whenever you required this uuid it will be fetched from keychain access. Even if app is deleted / replaced its unique.
Upvotes: 9
Reputation: 26385
Here some tests I made using identifierForVendor
on iOS7
After app installation: 28FD42B6-A993-4602-A988-69E375A1F913
After killing the app: 28FD42B6-A993-4602-A988-69E375A1F913
After deleting and reinstalling the app: 28FD42B6-A993-4602-A988-69E375A1F913
After system restore and reinstalling the app: 4948F77F-3D41-4933-B2F0-C4DCB529C7CC
After restore from backup made before system restore: 28FD42B6-A993-4602-A988-69E375A1F913
So the identifier for vender persists even after deleting and reinstalling the app only if there are application of the same vendor on the device.
The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.
The APNS token it should be used only as an identifier for sending push, it should not be related to a specific device by any means. Push tokens can change over time and you should de ready to manage that, this is stated in Apple documentation (even if I never see one changes even after disabling and reenabling them, it seems that it changes after iOS updates ).
Another is creating your UUID and saving it in the keychain, this will only be deleted only after a system restore.
If you want to save it in NSUserDefault
be aware that it is deleted with your app.
You can find interesting this post from NSHipster.
Upvotes: 2
Reputation: 1650
Keychain will reset if when you reset your device.
Unique id from "[[UIDevice currentDevice] identifierForVendor]" will change every time when you delete and re-install the app.
You are right, you should use the device token from APNS for unique id.
Upvotes: -1