Created
June 30, 2017 06:03
-
-
Save TheCodedSelf/bcf9c62173e9e2da334bd8292b87e4ae to your computer and use it in GitHub Desktop.
Basic example of using UIImagePickerController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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