我把ios-8的新touchID API添加到我的应用程序中。它通常如预期的工作,但当进入应用程序时,当我的手指已经在家庭按钮-API的成功回调被调用,但弹出仍然出现在屏幕上。按下“取消UI”之后,用户界面就变得没有响应能力。
发布于 2014-11-04 08:43:59
我还遇到了同样的问题,解决方案是使用高优先级队列调用对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 to是最佳的,但您的里程可能会有所不同。
更新(03/10/2015):几个iOS开发人员,比如1 1Password,iOS 8.2的are reporting最终解决了这个问题。
发布于 2014-11-20 10:54:30
虽然使用延迟可以潜在地解决问题,但它掩盖了根本原因。您需要确保只在应用程序状态处于活动状态时显示Touch ID对话框。如果在启动过程中立即显示它(这意味着应用程序在技术上仍然处于非活动状态),则可能会出现此类显示问题。这是没有记录的,我发现这很难。提供延迟似乎解决了这个问题,因为到那时,应用程序处于活动状态,但这并不有效。
为了确保它在应用程序处于活动状态时运行,您可以检查当前的应用程序状态,然后立即运行它,或者当我们收到applicationDidBecomeActive通知时。关于一个例子,见下文:
- (void)setup
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// We need to be in an active state for Touch ID to play nice
// If we're not, defer the presentation until we are
if([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
{
[self presentTouchID];
}
else
{
__weak __typeof(self) wSelf = self;
_onActiveBlock = ^{
[wSelf presentTouchID];
};
}
}
-(void)applicationDidBecomeActive:(NSNotification *)notif
{
if(_onActiveBlock)
{
_onActiveBlock();
_onActiveBlock = nil;
}
}
- (void)presentTouchID
{
_context = [[LAContext alloc] init];
_context.localizedFallbackTitle = _fallbackTitle;
[_context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:_reason
reply: ^(BOOL success, NSError *authenticationError)
{
// Handle response here
}];
}发布于 2014-11-08 15:49:43
这个公认的答案没有解决问题的根本原因:两次调用evaluatePolicy(),第二次调用正在进行中。因此,目前的解决方案有时只能靠运气,因为一切都取决于时间。
解决这个问题的直接方法是一个简单的布尔标志,以防止后续调用发生,直到第一个调用完成为止。
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
if ( NSClassFromString(@"LAContext") && ! delegate.touchIDInProgress ) {
delegate.touchIDInProgress = YES;
LAContext *localAuthenticationContext = [[LAContext alloc] init];
__autoreleasing NSError *authenticationError;
if ([localAuthenticationContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authenticationError]) {
[localAuthenticationContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:kTouchIDReason reply:^(BOOL success, NSError *error) {
delegate.touchIDInProgress = NO;
if (success) {
...
} else {
...
}
}];
}https://stackoverflow.com/questions/26463196
复制相似问题