4

I want to create an IBAction to open the iOS native camera app in my app, but I can't seem to find the address for the camera app online.

I know for messages it's: UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)

Does anyone know which is the correct scheme?

mugx
  • 9,869
  • 3
  • 43
  • 55
Theo Strauss
  • 1,281
  • 3
  • 19
  • 32

3 Answers3

5

I suggest you to follow a clean way doing so:

let cameraVc = UIImagePickerController()
cameraVc.sourceType = UIImagePickerControllerSourceType.camera
self.present(cameraVc, animated: true, completion: nil)

in such case you must add into the Info.plist:

<key>NSCameraUsageDescription</key>
<string>whatever</string>
mugx
  • 9,869
  • 3
  • 43
  • 55
0

Here we suggest you to user the following github :

https://github.com/shantaramk/AttachmentHandler

!. 1. Drag drop the AttachmentHandler folder in project folder

func showCameraActionSheet() {
    AttachmentHandler.shared.showAttachmentActionSheet(viewController: self)
    AttachmentHandler.shared.imagePickedBlock = { (image) in
        let chooseImage = image.resizeImage(targetSize: CGSize(width: 500, height: 600))
        self.imageList.insert(chooseImage, at: self.imageList.count-1)
        self.collectionView.reloadData()
    }
}
0

Swift 5 version, after adding NSCameraUsageDescription in your Info.plist:

let cameraVc = UIImagePickerController()
cameraVc.sourceType = UIImagePickerController.SourceType.camera
self.present(cameraVc, animated: true, completion: nil)
Abdul Karim Khan
  • 4,256
  • 1
  • 26
  • 30