【发布时间】:2018-10-02 15:15:22
【问题描述】:
我遇到了以下问题,我认为这是 iOS 12 中的一个错误。这在 iOS 11.4.1 中运行良好。请尝试以下操作。
在 Xcode 10 中打开一个新项目。添加一个 UI 按钮。将以下内容添加到您的 PLIST Privacy - Camera Usage Description 并附上一些描述。
复制以下代码:
import UIKit
class ViewController: UIViewController {
let imagePickerController = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func takePic(_ sender: Any) {
takePicture()
}
func takePicture() {
imagePickerController.allowsEditing = false
imagePickerController.sourceType = UIImagePickerController.SourceType.camera
imagePickerController.cameraCaptureMode = .photo
imagePickerController.modalPresentationStyle = .fullScreen
present(imagePickerController, animated: true, completion: nil)
}
}
将 UIButton 连接到 takePic IBAction。
在 iOS 12 设备上运行应用程序,因为模拟器没有摄像头。 UIImagePickerController 应该显示相机。
现在从 Xcode Targets-> Deployment Info 中的 Device Orientation 中删除 Portrait。再次运行,应用程序将崩溃并显示以下内容:
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [CAMViewfinderViewController shouldAutorotate] is returning YES'
*** First throw call stack:
(0x1d1ecff78 0x1d10c8284 0x1d1dd075c 0x1ff912b30 0x1ff913130 0x1ff9139a0 0x1ff8fcff0 0x1ff8d70bc 0x1ff8d6e84 0x1ff8d6e84 0x1ff8d6e84 0x1ff8d6e84 0x1ff8c9968 0x1ff8c982c 0x1ff8d9d88 0x1ff894ab4 0x1ff91dbb4 0x1ff550888 0x1ff904430 0x1ff21171c 0x1ff1fed44 0x1ff22fa84 0x1d1e5bfe0 0x1d1e56ab8 0x1d1e5703c 0x1d1e56844 0x1d4105be8 0x1ff205428 0x102f9d9f4 0x1d190c020)
libc++abi.dylib: terminating with uncaught exception of type NSException
这曾经适用于 iOS 11 的设备...
由于我有一个应用程序现在崩溃了,我如何以某种方式欺骗应用程序以在呈现 UIImagePickerController 之前欺骗应用程序处于纵向模式?
更新:似乎只在 iPhone X/XS 上崩溃
谢谢。
【问题讨论】:
-
我没有这个问题。在 iPhone 7 iOS 12 上测试。
-
您的应用程序支持哪些界面方向?
-
对我也很好。在 iPhone 7 plus 和 10.5 英寸 iPad Pro 上测试。当然,在 iPhone 中,相机控件始终是纵向的,但 iPad 上的控件无论调用应用程序使用什么都遵循方向。
-
跟进。 (1) 你忘了说应用程序需要有一个隐私密钥才能访问
info.plist中的相机。因此,我的应用程序第一次崩溃了。 (我的应用程序可以与相机和照片库一起使用,所以我立即知道原因是什么。(2)我在CAMViewfinderViewController上进行了 DuckDuckGo 搜索,发现的结果很少,但是 cmets 建议有一个(来自这里)这可能是问题吗?stackoverflow.com/questions/40377078/… -
感谢那些对此进行测试的人。你是对的,我在 iPhone 7 上测试过,它每次都能在 iPhone XS Max 上运行。
标签: swift uiimagepickercontroller landscape ios12 nsexception