在iPhone X/XS上横向模式下使用UIImagePickerController导致iOS 12应用程序崩溃

3
我遇到了以下问题,我认为这是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目标->部署信息中删除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 上进行了测试。 - Daniil Subbotin
你的应用程序支持哪些界面方向? - Sander Saelmans
对我来说也很好用。在iPhone 7 Plus和iPad Pro 10.5英寸上进行了测试。当然,在iPhone上,相机控件始终是竖屏的,但是iPad上的控件会根据调用应用程序的方向而变化。 - user7014451
1
感谢那些测试过这个程序的人。你们是正确的,我在iPhone 7上测试了它,它可以正常运行,但在iPhone XS Max上每次都会崩溃。 - Paul S.
雷达44972012已经装满了苹果。 - Paul S.
显示剩余4条评论
1个回答

0

我在iOS 12上使用iPhone X时遇到了同样的问题,解决方法如下:

  • 在项目文件中不设置任何界面方向
  • info.plist文件中定义初始界面方向,使用键Initial interface orientation和值Landscape (right home button)
  • 最后,在每个UIViewController中,您应该使用以下方式定义界面方向:

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .landscape }


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接