StartFirstResponder sometimes fails to open keyboard on ios 10

I create my own alert with a touch identifier with the code:

    let context = LAContext()

    guard deviceCanUseTouchId(context: context) else {
        return
    }

    presentingAlert = true
    [context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "touch_id_auth_message".localized(), reply: { [unowned self] success, error -> Void in
        self.presentingAlert = false
        self.canPresentAlert = true

        dispatch_async(dispatch_get_main_queue()) {    
            completionHandler?(success)
        }
    })]
Button handler

calling the Touch ID native notification is as follows:

@IBAction func touchUpInsideUseTouchIdButton(sender: AnyObject) {
    ACTouchId.sharedManager.authenticateWithTouchId(completionHandler: { [weak self] in
        self?.handleTouchIdAuthentication(granted: $0)
        })

    view.endEditing(true)
}

and this is the handleTouchIdAuthentication code:

private func handleTouchIdAuthentication(granted granted: Bool) {
    if granted {
        //...
    } else {
        passcodeDigitTextField1.becomeFirstResponder()
    }
}

The problem is that most of the time, when I cancel the native Touch ID dialog, the warning turns off correctly, and startFirstResponder () works fine.

However, about 1 time in 10 times, startFirstResponder () returns true, passcodeDigitTextField1 gets focus, but the keyboard does not appear. In addition, the keyboard will not be displayed even if I change focus to another text field by clicking on them.

Strange, this works fine for ios 9 and 8. The problem only happens on iOS 10 .

+4
4

:

. passcodeDigitTextField1.becomeFirstResponder() 0,25 0,5 Selector -

, 0.01

, .

+2

, Touch ID. , UIApplicationDidBecomeActiveNotification NSNotificationCenter becomeFirstResponder .

ApplicationDidBecomeActive Touch ID, .

, 100% . , .

+2

. , !

DispatchQueue.main.async {
      passcodeDigitTextField1.becomeFirstResponder()
}
+1

This may seem silly, but ... in my case, when it helped reboot the entire device. Only that. It was also iOS 10.;) Maybe there is someone with a similar problem and did not try to check it before checking the stack overflow, since it seems strange to just restart the device for such an error.

0
source

Source: https://habr.com/ru/post/1659196/


All Articles