"interfaceOrientation" is deprecated in iOS 8, How to change this method Objective C

Getting the device orientation is not correct. For instance, the device might be in landscape mode, but a view controller that only supports portrait will remain in portrait.

Instead, use this:

[[UIApplication sharedApplication] statusBarOrientation]

Another bonus is that it still uses the UIInterfaceOrientation enum, so very little of your code needs to change.


Since iOS8, Apple recommends to use TraitCollections (Size Classes) instead of interfaceOrientation.

Moreover, since iOS 9 and the new iPad feature "Multitasking", there are some cases where the device orientation doesn't fit with the window proportions! (breaking your application UI)

So you should also be very careful when using Regular Size Classes because it will not necessary take up the whole iPad screen.

Sometimes TraitCollections doesn't fill all your design needs. For those cases, Apple recommends to compare view's bounds :

if view.bounds.size.width > view.bounds.size.height {
    // ...
}

I was quite surprised, but you can check on the WWDC 2015 video Getting Started with Multitasking on iPad in iOS 9 at 21'15.

Maybe you're really looking for the device orientation and not for the screen or window proportions. If you care about the device camera, you should not use TraitCollection, neither view bounds.


Swift 4+ version

UIApplication.shared.statusBarOrientation