How do I know/get the list of supported orientations for my iOS app?

333 Views Asked by At

As a developer, I know the list of orientations added in the Project settings/plist for my iOS app, but I would like to know the list of supported orientations from the code.

For eg., one of the 3rd party SDK is returning UIInterfaceOrientationMask.landscapeLeft for one scenario and I would like to validate it in my viewcontroller before allowing the orientation.

And my application is crashing if I don't do it,

Crash -> Supported orientations has no common orientation with the application

1

There are 1 best solutions below

0
Glenn Posadas On

I know the list of orientations added in the Project settings/plist for my iOS app, but I would like to know the list of supported orientations from the code.

You can fetch your supported interface orientations from your info.plist like so:

let orientations = Bundle.main.infoDictionary?["UISupportedInterfaceOrientations"]

and then you'll get optional values array (that you can cast to array of Strings if you want to), like so:

▿ Optional<Any>
  ▿ some : 3 elements
    - 0 : UIInterfaceOrientationPortrait
    - 1 : UIInterfaceOrientationLandscapeLeft
    - 2 : UIInterfaceOrientationLandscapeRight