iOS 8 Touch ID error “User interaction is required.”

前端 未结 2 1172
迷失自我
迷失自我 2020-12-25 08:04

I have been working on integrating Touch ID support into an app I am working on. It is however acting very inconsistent. One of the common issues I am seeing is on a fresh a

2条回答
  •  一整个雨季
    2020-12-25 08:40

    @hetzi answer really helped me, but I have more to add on this.

    Basically this error happens when your app is woken up from background and somewhere on your code you are asking for Touch ID (my case is the local authentication type, I haven't tested with the keychain type). There's no way the user can interact with Touch ID prompted while the app is running on background, hence the error message.

    User interaction is required.

    The reasons my app was coming from background were: Push Notifications or Apple Watch.

    My fix is doing something like this on the viewDidLoad method of my initial VC:

    if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) {
        [self promptForTouchID];
    }
    

    I've used != because, when your app first launches it is in the UIApplicationStateInactive state. And that state doesn't generate a Touch ID error because the prompt will appear.

    I also call [self promptForTouchID] on a notification of UIApplicationWillEnterForegroundNotification, but since you know that the app will enter foreground, there's no need to check here.

提交回复
热议问题