PhotoPicker发现错误:Error Domain = PlugInKit Code = 13 [英] PhotoPicker discovery error: Error Domain=PlugInKit Code=13

查看:44
本文介绍了PhotoPicker发现错误:Error Domain = PlugInKit Code = 13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to display an image from the photo library in a UIImageView

完整错误是:

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

2017-06-09 21:55:59.063307+0200 firstapp2.0[12873:1120778] PhotoPicker discovery error: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

我的代码包含在下面:

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)
    }
}

推荐答案

我找到了这个解决方案.由于以下两个原因,导致出现此错误.

I found this solution. We got this error due to these two reason which is mentioned below.

  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.")
  }
}

  1. 正确的方法调用 didFinishPickingMediaWithInfo

错误:

Wrong:

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

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

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

I hope this solution will help you out to resolve this error.

如果对您有用,请别忘了将其标记为正确,这将有助于其他人找到正确的方法.

If it works for you don't forget to mark it's as a correct, so this will help to other to find the correct way.

这篇关于PhotoPicker发现错误:Error Domain = PlugInKit Code = 13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆