Pick image from gallery and open default camera for take photo in Swift

Use following variable

 var image : UIImage!
 var imagePicker = UIImagePickerController()
func presentActionSheet() {
        
        let settingsActionSheet: UIAlertController = UIAlertController(title:nil, message:nil, preferredStyle:UIAlertControllerStyle.actionSheet)
        settingsActionSheet.addAction(UIAlertAction(title:"Select From Gallery", style:UIAlertActionStyle.default, handler:{ action in
            self.photosGallary()
        }))
        
        settingsActionSheet.addAction(UIAlertAction(title:"Select From Camera", style:UIAlertActionStyle.default, handler:{ action in
            self.PhotosCamera()
        }))
        
        settingsActionSheet.addAction(UIAlertAction(title:"Cancel", style:UIAlertActionStyle.cancel, handler:nil))
        present(settingsActionSheet, animated:true, completion:nil)
    }
    
    func photosGallary() {
        imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
        imagePicker.delegate = self
        imagePicker.allowsEditing = true
        self.present(imagePicker, animated: true, completion: nil)
    }
    
    func PhotosCamera() {
        if(UIImagePickerController.isSourceTypeAvailable(.camera)){
            imagePicker.sourceType = UIImagePickerControllerSourceType.camera
            imagePicker.delegate = self
            imagePicker.allowsEditing = true
            self.present(imagePicker, animated: true, completion: nil)
        }
    }

 

use following delegate method for UIImagePickerController


extension ViewController : UIImagePickerControllerDelegate,UINavigationControllerDelegate
{
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        image = info[UIImagePickerControllerOriginalImage] as! UIImage
        
        dismiss(animated: true, completion: nil)
    }
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: true, completion: nil)
    }
}

Set following key in info.plist file

NSCameraUsageDescription
Use for take Profile image

NSPhotoLibraryUsageDescription
User for Pick Profile image