Deprecated iOS Methods: Rotation Setup

I haven’t updated my code for a while because I wanted to continue to support iOS5 on first generation iPads. Since Apple allows older devices to download older versions of the software, and my code in the App Store appears to be stable, I decided to update the existing code and get rid of deprecated code warnings. (I have 56 deprecated method warnings that I need to get rid of.)

First up is shouldAutorotateToInterfaceOrientation. This method, along with shouldAutorotate is sprinkled throughout my code because it was required for each view.

The old code, in the AppDelegate.m file, supported iOS 5-9 and looked like this:


#pragma mark - Handle rotation for different versions of the OS
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

// iOS 6 and above
- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    
    #ifdef UIInterfaceOrientationMaskAll
        return UIInterfaceOrientationMaskAll;  // iOS6+ method.
    #else
        return 0;
    #endif
}

I replaced it in the AppDelegate.m with this line:


- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

Update 2018-03-20
The current version of Xcode prefers that NSUInteger be replaced with UIInterfaceOrientationMask .

and removed lots of occurrences of shouldAutorotateToInterfaceOrientation.

“In iOS 6 and iOS 7, your app supports the interface orientations defined in your app’s Info.plist file.” Source

You don’t need to, but because I like to have clean code, I removed these lines in my .plist files:


<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

You can remove them with a text editor or using Xcode and deleting Supported interface orientations and Supported interface orientations (iPad).

Next up is willRotateToInterfaceOrientation and willAnimateRotationToInterfaceOrientation

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.