UIAlertController:supportedInterfaceOrientations was invoked recursively

This is a bug in iOS 9 that it failed to retrieve the supportedInterfaceOrientations for UIAlertController. And it seems it dropped to an infinite recursion loop in looking for the supportedInterfaceOrientations for UIAlertController (e.g., it tracks back to UIAlertControler -> UIViewController -> UINavigationController -> UITabBarController -> UIAlertController -> …), while the call to UIAlertController:supportedInterfaceOrientations actually … Read more

Prevent UIAlertController to dismiss

EDIT: Updated for Swift 5 EDIT: Updated to include @skywalker’s feedback So I actually got this to work. In short, it involves adding a long-press gesture recognizer to the UIAlertController that triggers before the dismissal occurs. First, create lazily loaded computed variables in your view controller for your UIAlertController and the UIAlertAction you want to … Read more

UIAlertController is Crashed (iPad)

To keep it device independent, rather use it as shown in the snippet below. This code will return nil for popoverPresentationController on an iPhone / compact size device, so you can safely use it in universal projects. if let popoverPresentationController = shareMenu.popoverPresentationController { popoverPresentationController.sourceView = self.view popoverPresentationController.sourceRect = sender.bounds } self.presentViewController(shareMenu, animated: true, completion: nil)

How to get input value from a UIAlertController text field?

Updated for Swift 3 and above: //1. Create the alert controller. let alert = UIAlertController(title: “Some Title”, message: “Enter a text”, preferredStyle: .alert) //2. Add the text field. You can configure it however you need. alert.addTextField { (textField) in textField.text = “Some default text” } // 3. Grab the value from the text field, and … Read more

UIAlertController text alignment

I have successfully used the following, for both aligning and styling the text of UIAlertControllers: let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = NSTextAlignment.Left let messageText = NSMutableAttributedString( string: “The message you want to display”, attributes: [ NSParagraphStyleAttributeName: paragraphStyle, NSFontAttributeName : UIFont.preferredFontForTextStyle(UIFontTextStyleBody), NSForegroundColorAttributeName : UIColor.blackColor() ] ) myAlert.setValue(messageText, forKey: “attributedMessage”) You can do a similar thing with … Read more

UIAlertController showing with delay

I was having the same issue with a UIAlertController presented by selecting a row from a UITableView. The first time everything worked fine, and then when the user triggered the alert again there was a few seconds delay before the alert was actually presented. As a workaround I used GCD: dispatch_async(dispatch_get_main_queue(), ^{ [self presentViewController:AlertView animated:YES … Read more

How to show UIAlertController from Appdelegate

try this Objective-C UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; topWindow.rootViewController = [UIViewController new]; topWindow.windowLevel = UIWindowLevelAlert + 1; UIAlertController* alert = [UIAlertController alertControllerWithTitle:@”APNS” message:@”received Notification” preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@”OK”,@”confirm”) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { // continue your work // important to hide the window after work completed. // this also keeps a reference … Read more

UIAlertController is moved to buggy position at top of screen when it calls `presentViewController:`

I encountered a situation where sometimes a modal view would present itself on top of a an alert (silly situation, I know), and the UIAlertController could appear in the top left (like the 2nd screenshot of the original question), and I found a one-liner solution that seems to work. For the controller that’s about to … Read more

Access input from UIAlertController

I’ve written up a blog post exploring the new API. You can just capture a local variable in the closure and you’re good to go. var inputTextField: UITextField? let passwordPrompt = UIAlertController(title: “Enter Password”, message: “You have selected to enter your password.”, preferredStyle: UIAlertControllerStyle.Alert) passwordPrompt.addAction(UIAlertAction(title: “Cancel”, style: UIAlertActionStyle.Default, handler: nil)) passwordPrompt.addAction(UIAlertAction(title: “OK”, style: UIAlertActionStyle.Default, handler: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)