iOS 9 beta - UIAlertController is not working

My app uses UIAlertController for both ActionSheet and Alert. It works fine on iOS 8, but if I run the code from xCode 7 beta on my iOS 9 device, this is not working properly. For action sheet, I can only see 'Cancel' button there ( while there is few other buttons I added ). And for Alert, I only see the background become a little darker, without any alert window/UI at all

Since I don't find any replacement for UIAlertController, I believe it is not deprecated yet. Can anyone here tell me how to use UIAlertController properly in iOS 9/xCode 7 ?

Thanks in advance

Replies

Can you supply a code snippet? I don't have any issues with UIAlertController, but I only use the UIAlertControllerStyleAlert style.

I notice if I remove this code:

[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];

from my AppDelegate, UIAlertController works fine


But I need that code to force everything to LTR even in RTL language. With above code in use, UIAlertController is not working like my post above


Here's my code for UIAlertControllerStyleAlert style:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action1 = [UIAlertAction actionWithTitle:[TheApp localizedStringForKey:@"NO" inTable:kDefaultStringsFile] style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

}];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:[TheApp localizedStringForKey:@"YES" inTable:kDefaultStringsFile] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

}];

[alertController addAction:action1];
[alertController addAction:action2];

[self presentViewController:alertController animated:YES completion:nil];


And ActionSheet:

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[TheApp localizedStringForKey:@"CANCEL" inTable:kDefaultStringsFile] style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
          
        }];
     
UIAlertAction *libraryAction = [UIAlertAction actionWithTitle:[TheApp localizedStringForKey:@"PHOTO_LIBRARY" inTable:kDefaultStringsFile] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
          
        }];
     
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:[TheApp localizedStringForKey:@"CAMERA" inTable:kDefaultStringsFile] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
          
        }];
     
[actionSheet addAction:cancelAction];
[actionSheet addAction:libraryAction];
[actionSheet addAction:cameraAction];
     
[self presentViewController:actionSheet animated:YES completion:nil];

I can reproduce this issue when the semanticContentAttribute is ForceRightToLeft:

UIView.appearance().semanticContentAttribute = UISemanticContentAttribute.ForceRightToLeft


I'm guessing if the default language is RTL, forcing LTR will is causing UIAlertController to lose content. Similarly, if default language is LTR, forcing RTL will cause UIAlertController to miss content...you should file a radar at bugreport.apple.com


Okay. Seems it is bug in iOS 9. I have reported this to Apple

Hi Yacob,


Why are you trying to force everything in LTR? Setting the semanticContentAttribute on the appearance proxy is not a supported configuration.

Hi all:


I solved this issue removing the LTR configuration for appearence proxy only for the UIAlertView and the UIAlertController like this:

// suppose you have alredy set the appearence to UISemanticContentAttributeForceLeftToRight


[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setSemanticContentAttribute:UISemanticContentAttributeUnspecified];

[[UIView appearanceWhenContainedIn:[UIAlertView class], nil] setSemanticContentAttribute:UISemanticContentAttributeUnspecified]; // my legacy code some times call alertview.