Skip to content

Instantly share code, notes, and snippets.

@TheCodedSelf
Created June 30, 2017 06:03
Show Gist options
  • Save TheCodedSelf/bcf9c62173e9e2da334bd8292b87e4ae to your computer and use it in GitHub Desktop.
Save TheCodedSelf/bcf9c62173e9e2da334bd8292b87e4ae to your computer and use it in GitHub Desktop.
Basic example of using UIImagePickerController
class ViewController: UIViewController {
func pickImage(fromSource sourceType: UIImagePickerControllerSourceType) {
guard UIImagePickerController.isSourceTypeAvailable(sourceType) else { return }
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = sourceType
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}
}
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
// handle image
} else if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
// handle image
}
picker.dismiss(animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment