iOS 8 Touch ID 错误 "User interaction is required."

标签 ios objective-c touch-id

我一直致力于将 Touch ID 支持集成到我正在开发的应用程序中。然而,它的行为非常不一致。我看到的一个常见问题是在新的应用程序启动时它按预期工作,但是在后台应用程序并将其带到前台时我从

返回错误
evaluatePolicy:localizedReason:reply:

它甚至没有多大意义(我从来没有看到 touchid 警报)

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

我已经尝试在应用程序已经运行时显示 touchid 警报,当它刚刚出现时,似乎并不重要。每次应用程序首次启动后,它都会中断。

还有其他人遇到这个问题吗?

作为引用,这是我正在使用的代码:

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

最佳答案

通常在进入后台之前推送 PIN View Controller :

- (void)applicationDidEnterBackground:(UIApplication *)application

因此,在翻阅应用预览图像(双击主页按钮)时,不会显示应用的内部信息。我猜你正在做类似的事情。

问题是 LocalAuthentication 的新 API 要求调用 viewController 可见。 这就是为什么你不应该在退出后台之前调用你的“showTouchID”功能。而是在进入前台时调用“showTouchID”函数:

- (void)applicationWillEnterForeground:(UIApplication *)application

它应该有效。 不要忘记在应用程序首次启动时调用它(在这种情况下 ..willEnterForeground 将不会被调用)。

关于iOS 8 Touch ID 错误 "User interaction is required.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25919482/

相关文章:

ios - 圆形 UIButton 不能对齐文本

ios - becomeFirstResponder 有时无法打开 ios 10 上的键盘

ios - Helvetica Neue Light,iOS

iphone - 在窗口模式下播放视频

ios - 我的应用程序崩溃时如何清理 NSUserDefault

ios - 充满 NSString 的 NSSet。当我将集合打印到控制台时,结果出乎意料

objective-c - NSTextField 和 FirstResponder

iphone - 在 UIImage 顶部绘制透明圆圈 - iPhone SDK

ios - 在 iOS 8.0 中使用数据库 Parse.com 登录用户的 TouchID

ios - iOS中的指纹实现