Created Project in Xcode 10.1 with Device Orientation Landscape Left and Right Only.
Added the following Key in Plist
Privacy - Camera Usage Description: “Used for taking Picture”
import UIKit
class UploadViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate
{
//MARK:- ViewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func cameraButtonAction(_ sender: UIButton)
{
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .camera
imagePicker.modalPresentationStyle = .overCurrentContext
imagePicker.delegate = self
self.present(imagePicker, animated: true, completion: nil)
}else{
let alert = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
Above code working fine in following devices
iPhone 8 (iOS 12)
iPhone 7 (iOS 11.4.1)
iPad mini (iOS 11)
But When I run this in iPhoneX with iOS 12.1, then Getting following error.
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:
libc++abi.dylib: terminating with uncaught exception of type NSException
I did the research on this issue but I'm not able to find the solution yet. Here are few links that I found for the related issue but none of the answers working for iPhoneX.
Using UIImagePickerController in landscape orientation