Sundog Expert Craig Isakson

Craig Isakson

Technical Architect

More Posts

Where did shouldAutorotateToInterfaceOrientation go in iOS 6?

If you are like me and wondering why your application’s orientation changes are not behaving correctly in iOS 6 but they worked just fine in iOS 5, then you may need to check your shouldAutorotateToInterfaceOrientation method in your view controllers. It turns out that with the release of iOS 6, Apple thought it would be a good thing to deprecate that method and not really provide any backwards compatibility for the new version to the old methods without code changes.

I ran into this issue while debugging an entirely different issue for an application for a client. It had taken me a while and also some searching through the tubes to find out why shouldAutorotateToInterfaceOrientation wasn’t being called. It turns out there are actually two methods that should be used instead for iOS 6; -(BOOL)shouldAutorotate and -(NSInteger)supportedInterfaceOrientations. If you are still supporting earlier versions of iOS you still need to keep shouldAutorotateToInterfaceOrientation and also include the two new methods. If you would like to support both and not duplicate any logic you already have created for your application, a simple solution I found was to use the following code:

    return YES;

    NSInteger orientationMask = 0;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
        orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
        orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
        orientationMask |= UIInterfaceOrientationMaskPortrait;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
        orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
    return orientationMask;

Setting the methods up this way means that shouldAutorotate and supportedInterfaceOrientations are only called by iOS 6. In supportedInterfaceOrientations, you are calling the already existing method shouldAutorotateToInterfaceOrientation passing in the different orientations to determine if you should support that orientation.

There is a lot of information on this subject. I found a lot of suggestions that did not work for me but this was the best solution I had found. If you are running into the same issue I hope this helps you figure it out. If you have a different solution that you have found that worked for you let us know in the comments!!

Posted in: Mobile, Software Development, Software Maintenance, Technical Strategy