NSException:"Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason:..."

NSException: "Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason:..."

这来自 iPhone 应用 swift:

*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', 
reason: 'Supported orientations has no common orientation with the application, 
and [UICompatibilityInputViewController shouldAutorotate] is returning YES
*** First throw call stack:
(0x1836984d0 0x198107f9c 0x183698418 0x188d7a1d0 0x188d833dc 0x188d83354     
0x188d81e3c 0x188cfe8fc 0x188cfdc0c 0x184581220 0x188cfda90 0x188d0ad08 
0x1895558e4 0x189556944 0x188d11af8 0x189556740 0x1895505d4 0x188dccd90 
0x18939b3dc 0x18939b5ec 0x18d43bb20 0x18d43bea0 0x18364fd6c 0x18364f800 
0x18364d500 0x18357d280 0x18e6f40cc 0x188d6adf8 0x100120d94 0x19894a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

我正在构建一个需要 phone 保持 'PortraitUpsideDown,' 以便后置摄像头始终位于底部的应用程序。为了反映这一点,我的 Info.plist 包括:

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>

该应用很小,只有一个视图控制器,其中包括

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.PortraitUpsideDown
}

override func shouldAutorotate() -> Bool {
   return false
}

应用程序有些自发地终止。我能够在不同的时间内构建和使用该应用程序,即我无法 "cause" 发生错误。

方向由三个文件决定:

  1. Info.plist

  2. 视图控制器

  3. AppDelegate

Info.plist 必须包括

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>

ViewController.swift 必须包含

override func shouldAutorotate() -> Bool {
        return false
    }
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
        return UIInterfaceOrientation.PortraitUpsideDown
    }

AppDelegate.swift 必须包含

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.PortraitUpsideDown
}