ios - Touch ID 导致应用程序无响应

标签 ios ios8 touch-id

我将 ios-8 的新 touchID API 添加到我的应用程序中。 它通常按预期工作,但是当我的手指已经在主页按钮上时进入应用程序时 - API 的成功回调被调用但弹出窗口仍然出现在屏幕上。按取消后 UI 变得无响应。

最佳答案

我也遇到了同样的问题,解决方案是使用高优先级队列调用 Touch ID API,并延迟:

// 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) {
                                ...
                            }
                        }];
  }
});

在测试我们的应用时,我们发现 750 毫秒的延迟是最佳的,但您的实际情况可能会有所不同。

更新 (03/10/2015): 一些 iOS 开发者,例如 1Password,are reporting iOS 8.2 终于解决了这个问题。

关于ios - Touch ID 导致应用程序无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26463196/

相关文章:

ios - 泄漏仪(iOS)发现的内存泄漏

iOS .addConstraint 只工作一次

ios - 我可以为我的应用程序禁用自定义键盘 (iOS8) 吗?

ios - TouchID 取消应该关闭 View Controller

iOS 生物认证 : Try Password work only after the second biometric fail attempt

ios - 不使用 Touch ID 登录

c# - OpenGL MonoTouch 游戏中的方向

iphone - 如何从 NSData 读取字节

ios - UICollectionView 什么时候请求它的数据?

ios - IOS 8 中的预处理器宏和 bool 值未正确评估