Miles Ressler
Miles Ressler

Reputation: 31

iOS DeviceCheck API - GenerateToken gives error Code 0

I'm trying to implement the new iOS 11 DeviceCheck API (https://developer.apple.com/documentation/devicecheck), but token generation always fails. I've tried on simulator and iPhone SE, with wifi and mobile data. Apple ID in settings is my normal, non-sandbox account.

This is an existing app for an organization - from the docs it sounds like the only configuration requirement is to make sure App ID is set up in the apple developer portal.

Anyone else having this issue?

The exact error message is:

The operation couldn’t be completed. (com.apple.devicecheck.error error 0.)

This is the code I'm using, nothing fancy.

if #available(iOS 11.0, *) {
        let device = DCDevice.current
        if (device.isSupported) {
            device.generateToken(completionHandler: { (data, error) in
                if let token = data{
                    print("token: \(token)")
                }else if let error = error{
                    print("error: \(error.localizedDescription)")
                }
            })
        } else {
            print("devicecheck not supported")
        }
    }

Upvotes: 3

Views: 3798

Answers (2)

atitpatel
atitpatel

Reputation: 3184

Your code seems fine to me. The problem is simulator. It won't pass device.isSupported. You need to run it on real device.

Upvotes: 1

abertsch
abertsch

Reputation: 103

In my case, this error was caused by my iPhone's time being horribly out of sync. I manually changed the device's time to be the actual, current time (Settings → General → Date & Time). After that, the error went away and I was able to generate tokens.

Upvotes: 4

Related Questions