Error iOS 8 Touch ID "User interaction required."

I am working on integrating Touch ID support into the application I'm working on. However, it is very incompatible. One of the common problems that I see is launching a new application that works as expected, but then, relying on the application and bringing it to the forefront, I get an error message from

evaluatePolicy:localizedReason:reply: 

It doesn't even make much sense (I never see a touch)

 Error Domain=com.apple.LocalAuthentication Code=-1004 "User interaction is required." UserInfo=0x171470a00 {NSLocalizedDescription=User interaction is required.} 

I tried to provide a touchid alert when the application is already running, when its just foreground does not seem to matter. It was broken every time after the first launch of the application.

Anyone else run into this?

For reference, here is the code I'm using:

 if (_useTouchId && [LAContext class]) { LAContext *myContext = [[LAContext alloc] init]; NSError *authError = nil; if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { _didPresentTouchId = YES; [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Use your Touch ID to open *****" reply:^(BOOL success, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^ { if (success) { _isClosing = YES; [self hide]; if (_successBlock) { _successBlock(); } } else if (error && error.code != -2 && error.code != -3 && error.code != -1004) { [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Authentication failed, please enter your Pin" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil] show]; } else { if (error) { DDLogError(@"TouchID error: %@", error.description); } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, .6 * NSEC_PER_SEC), dispatch_get_main_queue(), ^ { [self keyboardButtonTouched]; }); } }); }]; } } 
+7
ios objective-c touch-id
source share
2 answers

Typically, the PIN submission controllers are advanced before entering the background in:

 - (void)applicationDidEnterBackground:(UIApplication *)application 

Thus, the internal information of the application will not be displayed when swapping through the application’s preview images (“double” button). I think you are doing something similar.

The problem is that the new LocalAuthentication API requires the calling viewController to be visible. This is why you should not call your function showTouchID before going back to the background. Instead, call the showTouchID function when entering the foreground:

 - (void)applicationWillEnterForeground:(UIApplication *)application 

And that should work. Do not forget to call it the first time you launch the application (in this case .. willEnterForeground will not be called).

+7
source share

@Hetzi's answer really helped me, but I have something else to add.

Basically, this error occurs when your application wakes up from the background and somewhere on your code you request a Touch ID (my case is a local type of authentication, I have not tested it with a keychain type). It is not possible for the user to interact with the Touch ID tooltip when the application is running in the background, so there is an error message.

User interaction required.

The reasons for my application are: Push Notifications or Apple Watch .

My fix does something similar in the viewDidLoad method of my initial VC:

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

I used != Because when your application starts first, it is in the UIApplicationStateInactive state. And this state does not generate a Touch ID error because an invitation will appear.

I also call [self promptForTouchID] in the UIApplicationWillEnterForegroundNotification notification, but since you know that the application will come to the fore, there is no need to check here.

+3
source share

All Articles