我遇到了以下问题,我认为这是iOS 12中的一个错误。在iOS 11.4.1中功能正常。请尝试以下操作。
在Xcode 10中打开一个新项目,添加一个UI按钮。在您的PLIST中添加
复制以下代码:
在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目标->部署信息中删除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上崩溃。
谢谢。