3

I've come across the following, which I believe is a bug in iOS 12. This worked fine in iOS 11.4.1. Try the following.

Open a new project in Xcode 10. Add a UI button. Add the following to your PLIST Privacy - Camera Usage Description with some description.

Copy the following code:

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)
    }

}

Wire up the UIButton to the takePic IBAction.

Run the app on an iOS 12 device, since the simulator doesn't have a camera. The UIImagePickerController should show the camera.

Now remove Portrait from the Device Orientation in Xcode Targets-> Deployment Info. Run again and the app will crash with the following:

*** 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 

This used to work on devices on iOS 11...

Since I have an app that is now crashing, how do I somehow trick the app to tricking the app is in portrait mode before presenting the UIImagePickerController?

UPDATE: Appears to only crash on iPhone X/XS

Thanks.

Paul S.
  • 1,342
  • 4
  • 22
  • 43
  • I don't have this issue. Tested on iPhone 7 iOS 12. – Daniil Subbotin Oct 02 '18 at 15:25
  • What interface orientations do you support in your application? – Sander Saelmans Oct 02 '18 at 15:30
  • Works fine for me also. Tested on iPhone 7 plus and iPad Pro 10.5 inch. Of course, in iPhone, the camera controls are always in portrait, but the controls on the iPad followed the orientation no matter what to calling app uses. –  Oct 02 '18 at 15:36
  • Follow up. (1) You forgot to mention that the app need to have a privacy key for accessing the camera in `info.plist`. My app crashed the first time because of that. (My apps work with both the camera and photo library so I knew immediately what the cause was. (2) I did a DuckDuckGo search on `CAMViewfinderViewController` and found very few results, but there was one (from here) that the comments suggest that this may be the problem? https://stackoverflow.com/questions/40377078/ios-app-crashes-caught-by-crashlytics –  Oct 02 '18 at 15:42
  • 1
    Thanks to those who tested this. You're correct, I tested on iPhone 7 and it works, crashes on iPhone XS Max, every time. – Paul S. Oct 02 '18 at 15:53
  • @dfd I did, in fact, have the necessary key in my PLIST, I forgot to add it here. I did so in my edit. Thanks. – Paul S. Oct 02 '18 at 15:59
  • I figured you did. Best I can do is **SHOUT OUT** to anyone with an iPhone XS Max (details matter, so maybe iPhone X or iPhone XS) to see if you can replicate the issue. And with the updated question title - a deserved up-vote. –  Oct 02 '18 at 18:41
  • Radar 44972012 filled with Apple. – Paul S. Oct 03 '18 at 13:38
  • `UIImagePickerController` demands supporting [portrait orientation](https://developer.apple.com/documentation/uikit/uiimagepickercontroller) in your app – it is not a bug at all, you cannot use it on landscape-only apps (that applies to iPad as well) – holex Nov 06 '18 at 14:36

1 Answers1

0

I had the same problem with an iPhone X on iOS 12, what i did to solve it is :

  • Not setting any interface orientation in the project file
  • Defining an initial interface orientation in the info.plist file, using the key Initial interface orientation and the value Landscape (right home button)
  • Finally, in each of your UIViewController, you should define the interface orientation using for example:

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .landscape }