3

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")
        }
    }
Miles Ressler
  • 31
  • 1
  • 5

2 Answers2

4

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.

abertsch
  • 103
  • 2
  • 8
  • Did you have to get the exact time or was just the date fine? – d0nut Apr 24 '18 at 17:56
  • 1
    I went ahead and used the exact time. After a bit of testing it looks like there's about a +/- 5 minute window where you _won't_ get error 0. – abertsch Apr 24 '18 at 17:59
  • Gotcha, thanks for the update. This explains why I was getting this error earlier. – d0nut Apr 24 '18 at 18:53
  • 1
    I get this error on a device which passes device.isSupported and whose date & time is automatically updated, and as such correct to within a 5 minute window. We have app identifiers correctly set up in the developer portal. No idea why it isn't working :( – Alexander Gingell Jun 05 '19 at 12:54
1

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

atitpatel
  • 3,104
  • 1
  • 24
  • 34