Picker Error Message on Exit (encountered while discovering extensions: Error Domain=PlugInKit Code=13) With Swift 4 - Xcode 9

前端 未结 10 1129
生来不讨喜
生来不讨喜 2021-01-31 10:04

Similar to

PhotoPicker discovery error: Error Domain=PlugInKit Code=13

and also to

https://forums.developer.apple.com/thread/82105

BUT I have t

相关标签:
10条回答
  • 2021-01-31 10:35

    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
    
    0 讨论(0)
  • 2021-01-31 10:39

    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

    0 讨论(0)
  • 2021-01-31 10:44

    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.

    0 讨论(0)
  • 2021-01-31 10:44
    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

    0 讨论(0)
  • 2021-01-31 10:51

    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.

    0 讨论(0)
  • 2021-01-31 10:53

    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
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题