Skip to content

Instantly share code, notes, and snippets.

@francoismarceau29
Last active September 11, 2017 22:45
Show Gist options
  • Save francoismarceau29/e74fd0f7c3d41312fba3c15f6726790a to your computer and use it in GitHub Desktop.
Save francoismarceau29/e74fd0f7c3d41312fba3c15f6726790a to your computer and use it in GitHub Desktop.
Creating an UIImagePickerController
func takePhotoTouched() {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .camera
imagePicker.delegate = self
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
dismiss(animated: true) {
if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
let species = self.predict(image: image)
let alertController = UIAlertController(title: "Prediction", message: String(format: "The image is a %@", self.resultString(species: species)), preferredStyle: .alert)
let action = UIAlertAction(title: "Close", style: .default, handler: nil)
alertController.addAction(action)
self.navigationController?.present(alertController, animated: true, completion: nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment