PhotoPicker发现错误:错误Domain = PlugInKit Code = 13

Kre*_*doo 115 uiimage swift ios11

我正在尝试在UIImageView中显示照片库中的图像

完整的错误是:

2017-06-09 21:55:59.063307 + 0200 firstapp2.0 [12873:1120778] PhotoPicker发现错误:错误Domain = PlugInKit Code = 13"查询已取消"UserInfo = {NSLocalizedDescription =查询已取消}

我的代码包含在下面:

import UIKit

class ViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate{

    @IBOutlet weak var pic: UIImageView!
    @IBOutlet weak var text: UILabel!

    var chosenImage : UIImage!

    override func viewDidLoad() {
        super.viewDidLoad()        
        pic.isUserInteractionEnabled = true;
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [AnyHashable: Any]) {
        var chosenImage = info[UIImagePickerControllerEditedImage]
        self.pic!.image = chosenImage as! UIImage
        picker.dismiss(animated: true, completion: nil)
    }

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        picker.dismiss(animated: true, completion: nil)
    }

    @IBAction func tap(_ sender: Any) {        
        self.text.text = "Kreason"
        let imagePicker = UIImagePickerController()    
        imagePicker.delegate = self        
        imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
        imagePicker.allowsEditing = false    
        self.present(imagePicker, animated: true, completion: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 37

您需要明确的Objective-C参考: @objc

@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    image = chosenImage
    self.performSegue(withIdentifier: "ShowEditView", sender: self)
    dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

  • 适合我.我最近更新到Swift 4和Xcode 9,这解决了它. (6认同)
  • 适合我.迁移到Swift 4.0后需要. (3认同)
  • 不行.我调用`dismiss`后发生了这个错误. (3认同)

小智 18

我找到了这个解决方案 由于下面提到的这两个原因,我们得到了这个错误.

  1. 首先,我们需要调用此方法进行授权

授权码

func checkPermission() {
  let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus() switch photoAuthorizationStatus {
    case .authorized: print("Access is granted by user")
    case .notDetermined: PHPhotoLibrary.requestAuthorization({
      (newStatus) in print("status is \(newStatus)") if newStatus == PHAuthorizationStatus.authorized { / do stuff here */ print("success") }
    })
    case .restricted: / print("User do not have access to photo album.")
    case .denied: / print("User has denied the permission.")
  }
}
Run Code Online (Sandbox Code Playgroud)
  1. 正确的方法调用 didFinishPickingMediaWithInfo

错误:

private func imagePickerController( picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
} 
Run Code Online (Sandbox Code Playgroud)

@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
} 
Run Code Online (Sandbox Code Playgroud)

我希望此解决方案可以帮助您解决此错误.

如果它适用于你,不要忘记将它标记为正确,所以这将有助于其他人找到正确的方法.


小智 17

我找到了!它试图告诉您,您没有"照片"的授权您需要#import <Photos/Photos.h>在Objective-C中包含和请求授权,例如此类.

希望这会为你节省一些时间.我整整花了两天时间调试这个!

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
    switch (status) {
        case PHAuthorizationStatusAuthorized:
            NSLog(@"PHAuthorizationStatusAuthorized");
            break;
        case PHAuthorizationStatusDenied:
            NSLog(@"PHAuthorizationStatusDenied");
            break;
        case PHAuthorizationStatusNotDetermined:
            NSLog(@"PHAuthorizationStatusNotDetermined");
            break;
        case PHAuthorizationStatusRestricted:
            NSLog(@"PHAuthorizationStatusRestricted");
            break;
    }
}];
Run Code Online (Sandbox Code Playgroud)

我相信有人可以告诉你如何在Swift中做同样的事情.

  • 这并没有解决我的问题. (6认同)

小智 15

尝试了一些组合响应但没有取得多大成功.

使用Swift 4,我发现我需要确保实现以下两个项目以确保选择图像并将其放入选择器中(请注意发现扩展时遇到的"[发现]错误:

错误域= PlugInKit代码= 13"查询已取消"UserInfo = {NSLocalizedDescription = query canceled}"

消息仍然显示在控制台中,但它不会阻止您添加图像).也许这是一条消息导致选择器被解雇?

1)对委托UIImagePickerController(UIImagePickerControllerDelegate & UINavigationControllerDelegate)?所以需要明确添加UINavigationControllerDelegate作为协议之一:

class ViewController:UIViewController, UIImagePickerControllerDelegate, 
    UINavigationControllerDelegate { .... }. 
Run Code Online (Sandbox Code Playgroud)

2)确保info.plist设置了Privacy - Photo library Usage Description密钥和字符串值.

当然,你需要确保你创建UIImagePickerController及其委托等于设定selfViewDidLoad():

class ViewController:UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 
    let imagePickerController = UIImagePickerController()
    override func viewDidLoad() {
        super.viewDidLoad()
        imagePickerController.delegate = self
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

  • 我在我的项目中有所有这些..仍然没有用 (4认同)

小智 11

我修复了这个问题,将下面的函数调用到viewdidload或viewWillAppear或viewDidAppear来检查你的应用程序的权限.

func checkPermission() {
        let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
        switch photoAuthorizationStatus {
        case .authorized:
            print("Access is granted by user")
        case .notDetermined:
            PHPhotoLibrary.requestAuthorization({
                (newStatus) in
                print("status is \(newStatus)")
                if newStatus ==  PHAuthorizationStatus.authorized {
                    /* do stuff here */
                    print("success")
                }
            })
            print("It is not determined until now")
        case .restricted:
            // same same
            print("User do not have access to photo album.")
        case .denied:
            // same same
            print("User has denied the permission.")
        }
    }
Run Code Online (Sandbox Code Playgroud)

并且要使用上面的方法,不要忘记import Photos在类的顶部添加.


FRI*_*DAY 11

XCODE 10.1 / SWIFT 4.2:

  1. 添加所需的权限(提及其他权限)

  2. 实现此委托函数:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    
        if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
            self.imgView.contentMode = .scaleAspectFit
            self.imgView.image = pickedImage
        }
    
        dismiss(animated: true, completion: nil)
    }
    
    Run Code Online (Sandbox Code Playgroud)


Dan*_*rde 10

*在Swift 3中缺少DELEGATE*

在我的例子中,所有设置都是正确的:
1 - Delegates(UIImagePickerControllerDelegate,UINavigationControllerDelegate);
2 - 已经验证的权限;
3 - Plist已经完成;
4 - 在这个答案中读到的一切,我做到了;

但我忘了来实现pickerview.delegate = selfviewDidLoad 由于我复制和我的其他的viewController粘贴和忘记了!

我希望它可以帮助某人,首先检查你的COPY/PASTE!


小智 8

这可能不是最直接有用的答案-但希望它将有所帮助!我有99%的把握确定此特定的错误消息实际上并未将您引向真正的问题。我花了几个小时才解决这个同样的问题。

1)启动选择器时,我已获得将照片打印到控制台的授权; 2)我可以足够轻松地导航和选择照片;以及3)取消选择器后,我回到视图中时,按钮图像未使用新照片进行更新...,而我对问题的唯一提示是收到的消息完全相同。

原来我是在ViewWillAppear中而不是ViewDidLoad中对占位符图像进行硬编码。每次取消选择器时,都会调用ViewWillAppear并将我选择的图像替换为我的硬编码图像。我已经解决了这个问题,而且确实可以确定-一切现在都正常工作了。每次从选择器返回时,我仍然看到错误消息。

我建议您查找除ImagePicker之外的其他地方,以解决问题。


Cha*_*ong 8

如果你还没有这样做,试试这个.

产品>方案>编辑方案>环境变量 OS_ACTIVITY_MODE: disable

它解决了我的问题.

  • 这会抑制错误消息,但不会解决其原因.它还抑制了其他系统消息以及来自`NSLog`的任何内容. (21认同)
  • 这不是"解决"问题,只是让它看不见.非常糟糕的做法. (5认同)
  • 你能解释为什么这个有效吗? (2认同)

use*_*553 7

这可以解决Swift 4中的问题:

更改下面的代码

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {}
Run Code Online (Sandbox Code Playgroud)

对此:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {}


Swift 4.2 update:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){}
Run Code Online (Sandbox Code Playgroud)


小智 5

当我尝试从选择器回调中呈现另一个控制器时,我得到了相同的消息imagePickerController。对我有用的解决方案是将我的代码从picker dismiss方法的完成回调内移动

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        picker.dismiss(animated: true) {
            if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
                let cropController:CropViewController = CropViewController(croppingStyle: .circular, image: pickedImage)
                cropController.delegate = self
                self.present(cropController, animated: true, completion: nil)
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)