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.