Last active
April 12, 2017 20:40
-
-
Save danielt1263/97f2413c7a3fc445e3c867d98842eaa5 to your computer and use it in GitHub Desktop.
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 ImagePickerDelegate: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate | |
{ | |
let promise = Promise<UIImage>() | |
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { | |
if let image = (info[UIImagePickerControllerEditedImage] as? UIImage) ?? (info[UIImagePickerControllerOriginalImage] as? UIImage) { | |
promise.fulfill(image) | |
} | |
else { | |
promise.reject(UIImagePickerControllerError.missingImage) | |
} | |
} | |
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { | |
promise.reject(UserInteractionError.userCanceled) | |
} | |
} | |
enum UIImagePickerControllerError: Error { | |
case missingImage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment