From UUID to VenderId to Mac address, every developer is looking for a unique identifier that can track users and devices. Unfortunately, since UUID usage has been restricted, there hasn’t been a identifier similar to the original UUID.

DeviceCheck is a new framework in iOS11 that allows you to communicate with Apple servers via your own server and set up two bits of data for a single Device. Only two bool values can be stored. The framework offers a better option for tracking users, but for now it only stores information such as whether a user has used a promo code or whether the current device is suspected of fraud, such as brushing.

Introduction to iOS Integration

The basic flow of DeviceCheck is as follows: 1. Use the DeviceCheck APIs within the App to obtain a temporary token to mark the device (which will soon fail) 2. Then the back-end server uses the token and the authenticated key (from Apple’s certificate request module) to request the Apple server to update or query the value of the device. 3. The Apple server returns the information of the back-end server to obtain the information previously stored on the device. Contains bits information and the timestamp of the last modification

On the server side, Http Post requests are used to query and update information. The header of each request should contain an authenticated key value (JWT) from Apple. To obtain this token, you can use a similar process like Apple’s Push Service (APNs). For details, see Communicate with APNs using Authentication Tokens.

The API requested by the server can be accessed and executed according to the following example:

Address: Apple API development environment: api.development.devicecheck.apple.com online environment: api.devicecheck.apple.com.

After the request is complete, you can obtain/update the latest device information. Then you can use the information for service operations.

Use the API

It is currently found that this API is not available in Swift, possibly a bug at the moment. However, you can run it in a Swift project by bridging oc code. A code example is as follows:

+ (NSString *)getNewDeviceId {
    if ([DCDevice.currentDevice isSupported]) {
        [DCDevice.currentDevice generateTokenWithCompletionHandler:^(NSData * _Nullable token, NSError * _Nullable error) {
            if (error) {
                NSLog(@"%@", error.description);
            } else {
                // upload token to APP server
                NSString *deviceToken = [token base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
                NSLog(@"%lu %@", token.length, deviceToken);
            }
        }];
    }
    return @"";
}Copy the code
reference
  1. Developer.apple.com/documentati…
  2. Developer.apple.com/documentati…