I want to add images from photo library or by using camera to my ipad application. I had used same coding as iphone . But the application is crashing. I think this is not t
for Swift 4
get image from camera
let picker = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = true
picker.sourceType = .camera
self.present(picker, animated: true, completion: nil)
get image from library
let picker = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = true
picker.sourceType = .photoLibrary
self.present(picker, animated: true, completion: nil)
delegate function
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
var result = false
if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
//do something to image here ...
picker.dismiss(animated: true, completion: nil)
}
}
In your view controller, don't forget to inherit class UIImagePickerControllerDelegate, UINavigationControllerDelegate