Search code examples
iosios8touch-id

Touch ID causing app to become non-responsive


I Added ios-8's new touchID API to my app. It usually works as expected, BUT when entering app while my finger is already on home-button - API's success callback is called but pop-up still appears on screen. after pressing CANCEL UI becomes non-responsive.


Solution

  • I also encountered the same issue, and the solution was to invoke the call to the Touch ID API using a high priority queue, as well as a delay:

    // Touch ID must be called with a high priority queue, otherwise it might fail.
    // Also, a dispatch_after is required, otherwise we might receive "Pending UI mechanism already set."
    dispatch_queue_t highPriorityQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.75 * NSEC_PER_SEC), highPriorityQueue, ^{
      LAContext *context = [[LAContext alloc] init];
      NSError *error = nil;
    
      // Check if device supports TouchID
      if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
          // TouchID supported, show it to user
          [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:@"Unlock Using Touch ID"
                            reply:^(BOOL success, NSError *error) {
                                if (success) {
                                    // This action has to be on main thread and must be synchronous
                                    dispatch_async(dispatch_get_main_queue(), ^{
                                        ...
                                    });
                                }
                                else if (error) {
                                    ...
                                }
                            }];
      }
    });
    

    When testing our app, we found a delay of 750ms to be optimal, but your mileage may vary.

    Update (03/10/2015): Several iOS developers, like 1Password for example, are reporting that iOS 8.2 have finally fixed this issue.