Can the `DeviceCheck` API generate a token when there is no internet connection?

606 Views Asked by At

Can the DeviceCheck API generate a token when the device is offline?

if DCDevice.curDevice.isSupported {
    DCDevice.current.generateToken(completionHandler: { (data, error) in
        if let tokenData = data {
            print("Received token \(tokenData)")
        }
        else {
            print("Hit error: \(error!.localizedDescription)")
        }
    })
}
2

There are 2 best solutions below

0
On

Device token can be received in offline mode too.

Device tokens can change after updating the operating system, and always change when a device's data and settings are erased

0
On

The key can be generated offline by making use of generatekey API. However, while calling attestkey API to get the attestationObject, it will make a call to Apple's servers hence attestation will fail if tried in offline mode.

Some side notes to ensure the quality design of this solution -

  1. While making attestkey API call, it can take considerable time (even upto 4 seconds at times).
  2. Apple wants these calls to be made only when really needed and in a sensible way. In the documentation, it is mentioned HTTP error 429 will be thrown for too many requests. There is no information about a maximum number of requests per min/hour, unfortunately.