当应用程序在 TouchID 后激活时键盘不可见

Invisible keyboard when app becomes active after TouchID

我有一个安全控制器,它可以在应用程序激活时触发 Touch ID。如果用户取消 Touch ID 框,则会显示一个键盘以输入数字代码。但是我的键盘已加载(inputAccessoryView 绘制在正确的位置)但不可见。我需要将应用背景和前景设置为键盘可见。

我尝试了这个不起作用的解决方案:Super slow lag/delay on initial keyboard animation of UITextField

if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString
    reply:^(BOOL success, NSError *error) {
        if (success) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"User authenticated successfully, take appropriate action");
            });
        } else {
            NSLog(@"User did not authenticate successfully, look at error and take appropriate action");

            dispatch_async(dispatch_get_main_queue(), ^(void){
                [self._fieldSecurity becomeFirstResponder];
            });
        }
    }];
} else {
    NSLog(@"Could not evaluate policy; look at authError and present an appropriate message to user");
    dispatch_async(dispatch_get_main_queue(), ^{
        [self._fieldSecurity becomeFirstResponder];
    });
}

作为临时修复,延迟调用 becomeFirstResponder(通过使用 dispatch_after)但仍在主队列中。

我对这个问题的猜测是,TouchID 视图位于另一个 window 而不是应用程序的正常 window。当用户取消 TouchID 授权时,TouchID window 仍然是键 window,因此在下面 window 上调用您的 UITextField 会弹出键盘。但正如我所说,这只是一个猜测。

更新代码:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void){
    // Pop the keyboard
});