Similar to
PhotoPicker discovery error: Error Domain=PlugInKit Code=13
and also to
https://forums.developer.apple.com/thread/82105
BUT I have t
Make sure you declare that your class implements UINavigationControllerDelegate
.
extension MyViewController: UINavigationControllerDelegate {}
For some reason in Xcode 9.0 it warned me to declare the delegate as such:
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
The user asks: "*Any suggestions how to stop the error message? Other than the list of things offered at the other two links (summarized above)".
I used two steps to eliminate the error message.
Kudos to the person above Antoine Richeux https://stackoverflow.com/users/5767821/antoine-richeux.
I think the Privacy addition to pList may not be necessary, at least in my case
STEP 1. From the Menu bar select: Product > Scheme > Edit Scheme > select Run from the left side list of Build, Run ... Archive Select Arguments from top set of selections on right side - see picture attached. Use the + button under Environment Variables to add a new entry Name: OS_ACTIVITY_MODE Value: disable
This shows where to add the environment variable
STEP 2. Clean the project and rebuild
I had the same issue and tried every solution I could find, but nothing helped. Just asked myself what could happen to the delegate to not being triggered: deallocation of the delegate!
And that was it in my case! When presenting the UIImagePickerController my instance of class ImagePickerController : NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate
which isn't the presenting view controller, will be deallocated directly. Of course the delegate functions can't be executed anymore.
Just put a breakpoint in deinit
(or dealloc
in Objective-C world) and see if your delegate is being deallocated.
var messageImage = UIImage()
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
self.dismiss(animated: true, completion: { () -> Void in
})
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
{
messageImage = image
}
print("Image Captured")
}
You need to fetch UIImagePickerController.InfoKey.originalImage
not UIImagePickerController.InfoKey.editedImage
It is because your app uses photo library (in this case, using UIImagePickerController
) without asking for user permission. As an example, if I want to show the image picker when the add button was tapped:
@IBAction func addButtonTapped(_ sender: UIBarButtonItem) {
checkPermission {
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
picker.delegate = self
picker.allowsEditing = false
self.present(picker, animated: true, completion: nil)
}
}
func checkPermission(hanler: @escaping () -> Void) {
let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
switch photoAuthorizationStatus {
case .authorized:
// Access is already granted by user
hanler()
case .notDetermined:
PHPhotoLibrary.requestAuthorization { (newStatus) in
if newStatus == PHAuthorizationStatus.authorized {
// Access is granted by user
hanler()
}
}
default:
print("Error: no access to photo album.")
}
}
In addition, need to add this to your plist as well:
<key>NSPhotoLibraryUsageDescription</key>
<string>So that you can add images for your cloth. </string>
which is the message displayed in the permission dialog.
Can you try it out ?
extension YourProfileViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
log.debug("Called imagePickerController function ")
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true) {
self.yourProfileImageView.image = image
}
}
}