Unique Identifier for the iOS Devices
Why to Identify devices?
- Did this device already consume a free trial?
- Has this device paid for content but not linked that purchase to an account?
- Was this device previously enrolled for offer by user?
What different approaches, we are aware and using it in our implementation?
1. Get a unique device ID and store that on the server. Since UDIDs are no longer allowed, that’s out.
[[UIDevice currentDevice] uniqueIdentifier]
2. Use something like the advertising ID. Trouble is, user can reset that and get a new one. Used only for serving advertisement.
3. Use something like vendor identifier. Uniquely identifies the device to the app’s vendor. The value changes when user deletes all the vendor’s apps from the device and reinstalls one or more of them.
4. Write a unique ID into the keychain or user preferences. User can delete app, reinstall, and redeem item again.
NSUUID *UUID = [NSUUID UUID];
NSString* stringUUID = [UUID UUIDString];
5. Rely on user login. But then the user can create a dummy account and keep redeeming multiple times.
To get more information you can check http://nshipster.com/uuid-udid-unique-identifier/
What’s new?
Apple has come up with the DeviceCheck framework in iOS 11.
Access per-device, per-developer data that your associated server can use in its business logic.
NOTE: Developer are still responsible for keeping track of whether users has already redeemed offers that you have provided.
Let’s go steps by steps,
1. Query for token — Use DCDevice class has a generateToken method which will generate the token.
2. Send token to app server — Send received token to your application server.
3. Set two bits — Application server will responsible for sharing this token and set the bit value.
“device_token” : “wlkCDA2Hy/CfMqVAShslBAR/0sAiuRIUm5jQg0a…”
“transaction_id” : “5b737ca6-a4c7–488e-b928–8452960c4be9”,
4. Delete Application — Delete the application from device
8. Query two bit — Request to Apple to query bit state
“device_token” : “wlkCDA2Hy/CfMqVAShslBAR/0sAiuRIUm5jQg0a…”
“transaction_id” : “5b737ca6-a4c7–488e-b928–8452960c4be9”,
9. Response from Apple server –
//***************************************************************//
Class: DCDevice
This class represent the device and has only three methods as mentioned below,
class var current: DCDeviceThe device for which to perform the check.var isSupported: BoolA Boolean value indicating whether the DeviceCheck APIs are available on the current device.func generateToken(completionHandler: (Data?, Error?) -> Void)Generates a token that identifies the current device.Generate a new device token that can be used to get/set the persistent bits for this device. This call generates a new value every time.//***************************************************************//
Reference:
WWDC 2017 — Session 702 — iOS, macOS, tvOS, watchOS
https://developer.apple.com/videos/play/wwdc2017/702/
https://developer.apple.com/documentation/devicecheck/accessing_and_modifying_the_per_device_data