UIAlertView crashs in iOS 8.3
Asked Answered
H

6

11

recently i start receiving crash reports for UIAlertView only by users that use iOS 8.3

Crashlytics reports:

Fatal Exception: UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application, and [_UIAlertShimPresentingViewController shouldAutorotate] is returning YES

The line where that crash happens is [alertView show] :

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                    message:message
                                                   delegate:nil
                                          cancelButtonTitle:cancelButtonTitle
                                          otherButtonTitles:nil];
[alertView show];

that code is in the app for a long time and now it starts crashing. Did anyone experience a similar behaviour and has fixed the problem?

Heartache answered 9/4, 2015 at 9:0 Comment(5)
Its deprecated in iOS 8.Metallophone
i know - but deprecated things should still be working and it worked well in ios 8.0, 8.1 and 8.2. Since my App also supports iOS 7 and i don't want to introduce conditionals for the UIAlertView calls i decided to still keep the old code as long as its supportedHeartache
I get the same error with UIAlertControllers. Subclassing UIAlertController (or UIAlertView) should fix the issue.Commercialize
@Commercialize Apple explicitly says not to subclass UIAlertView or UIAlertController in the docs. See the answers below.Belemnite
@Belemnite You're right. Which class am I supposed to override those methods? I tried the view controller that's presenting the UIAlertController, but the crash persists.Commercialize
S
9

try by implementing this

- (BOOL)shouldAutorotate {
   return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

check this also : Orientation issue in Lanscape mode while opening camera in iOS 7 in iPhone

Seafaring answered 9/4, 2015 at 9:18 Comment(3)
I thought i had this in, but i accidentaly used UIDeviceOrientationPortrait instead of UIInterfaceOrientationMaskPortrait.Heartache
Added above method but still issue with my appDacha
This solved my issue. Replacing Alertview will be a hell lot of work :)Involucre
E
10

The main thing is :

UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application

It means you have somewhere implemented

- (NSUInteger)supportedInterfaceOrientations {

    return UIDeviceOrientationPortrait; // or UIInterfaceOrientationPortrait
}

UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait = 0

In that function MUST be returned Mask like:

UIInterfaceOrientationMaskPortrait which is 1

Echolocation answered 28/4, 2015 at 9:12 Comment(0)
S
9

try by implementing this

- (BOOL)shouldAutorotate {
   return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

check this also : Orientation issue in Lanscape mode while opening camera in iOS 7 in iPhone

Seafaring answered 9/4, 2015 at 9:18 Comment(3)
I thought i had this in, but i accidentaly used UIDeviceOrientationPortrait instead of UIInterfaceOrientationMaskPortrait.Heartache
Added above method but still issue with my appDacha
This solved my issue. Replacing Alertview will be a hell lot of work :)Involucre
T
1

Better than this you should start using UIAlertController. It has much better functionality and also for UIAlertAction you don't have to include delegate methods.

UIAlertController * alert=   [UIAlertController
                             alertControllerWithTitle:@"Info"
                             message:@"You are using UIAlertController"
                             preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* ok = [UIAlertAction
                    actionWithTitle:@"OK"
                    style:UIAlertActionStyleDefault
                    handler:^(UIAlertAction * action)
                    {
                        [alert dismissViewControllerAnimated:YES completion:nil];

                    }];

UIAlertAction* cancel = [UIAlertAction
                        actionWithTitle:@"Cancel"
                       style:UIAlertActionStyleDefault
                       handler:^(UIAlertAction * action)
                       {
                           [alert dismissViewControllerAnimated:YES completion:nil];

                       }];

[alert addAction:ok];

[alert addAction:cancel];

[self presentViewController:alert animated:YES completion:nil];
Tingle answered 9/4, 2015 at 9:8 Comment(0)
M
0

Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert.

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAlertView_Class/index.html

Metallophone answered 9/4, 2015 at 9:6 Comment(0)
L
0

After trying the solutions here, none of them worked for me. I'm supporting iOS 6-8 in an app, and, more than that, use some libraries that use UIAlertView internally, so simply conditionally compiling to use UIAlertController when available was not an option.

I came up with a solution that solved the problem for me. Your mileage may vary. I include the header file in the Header Prefix file so that it's sure to be included anywhere a UIAlertView is shown.

I'm posting this here for anyone who's stumbling on this problem and the solutions found around the net don't work. Hopefully it's helpful.

https://gist.github.com/joshhudnall/cdc89b61d0a545c85d1d

Lobito answered 28/4, 2015 at 23:19 Comment(0)
L
0

I created a helper for displaying UIAlertView when before iOS8 and UIAlertController after iOS8, this solves the rotation crash and also displays nicely in all versions.

https://github.com/dannyshmueli/DSAlertDisplayer

Lang answered 21/5, 2015 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.