IOS 9 - Keyboard appears after rejecting UIAlertView

I have a strange visual error that only affects iOS 9 devices:

The login to my applications the UIViewController disabled and gets the OAuth token when you click the button as expected. If the response from my API returns a specific status code, I display a UIAlertView message that needs to reset their password (if they were marked as such on the server). resignFirstResponder login and password resignFirstResponder after clicking a button, standard material.

Only on iOS 9, if you press the reset path, the second one you click OK on this warning screen, the keyboard will return, possibly for 800 ms, and then quit again. It was almost as if something had been queued up to represent him, but the presence of a warning blocked him until you click OK - it was absolutely instantly after being hit in order upon notification.

It seems very difficult to debug. Ive added symbolic breakpoints to becomeFirstResponder , and it is not called anywhere near this process.

Any other ideas how I can look at debugging / fixing this? This does not affect iOS 7 and iOS 8, only iOS 9.

+5
source share
2 answers

I ran into this problem about 30 minutes ago.

UIAlertView has been deprecated since iOS9 was released.

We solved this problem with the UIAlertController, for example:

  UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert Title!" message:@"This is an alert message." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:ok]; [self presentViewController:alertController animated:NO completion:nil]; 

This should solve your problem.

If animated = YES, you may get the same problem as before. This is a bug with iOS9.

Let me know how this happens and if it fixes your problem.

+13
source

Here is an extension to handle this in swift 3

 extension UIViewController { func presentOk(with title: String, and message: String, handler: ((UIAlertAction) -> Void)?) { let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: handler)) OperationQueue.main.addOperation { self.view.endEditing(true) self.present(alert, animated: true, completion: nil) } } } 

The key is to hide the keyboard and present the controller in the main queue.

Using

 presentOk(with: "My app title", and: "this is the alert message", handler: nil) 
0
source

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


All Articles