我如何知道/获取我的iOS应用程序支持的方位列表?

问题描述

作为开发人员,我知道在iOS应用程序的“项目设置/ plist”中添加的方向列表,但是我想从代码中了解受支持的方向列表。

例如,一个第三方SDK之一针对一种情况返回了UIInterfaceOrientationMask.landscapeLeft,我希望在允许定向之前在我的视图控制器中对其进行验证。

如果我不这样做,我的应用程序将崩溃,

崩溃-> Supported orientations has no common orientation with the application

解决方法

我知道在项目设置/ plist中添加的方向列表 适用于我的iOS应用,但我想知道支持的列表 代码的方向。

您可以像这样从info.plist获取支持的界面方向:

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

,然后您将获得可选的值数组(可以将其转换为字符串数组),如下所示:

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