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

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


完整的错误是:


2017-06-09 21:55:59.063307 + 0200 firstapp2.0 [12873:1120778] PhotoPicker发现错误:Error 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)

    }

}


江户川乱折腾
浏览 895回答 3
3回答

哆啦的时光机

您需要明确的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)}

倚天杖

我找到了解决方案。由于以下两个原因,导致出现此错误。首先,我们需要调用此方法进行授权授权码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.")  }}正确的方法调用 didFinishPickingMediaWithInfo错误:private func imagePickerController( picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {} 对@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {} 希望此解决方案可以帮助您解决此错误。如果对您有用,请别忘了将其标记为正确,这将有助于其他人找到正确的方法。

白板的微信

我找到了!它试图告诉您您没有“照片”的#import <Photos/Photos.h>授权。例如,需要在Objective-C中包括和请求这样的授权。希望这可以节省您一些时间。我花了整整两天的时间进行调试![PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {&nbsp; &nbsp; switch (status) {&nbsp; &nbsp; &nbsp; &nbsp; case PHAuthorizationStatusAuthorized:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@"PHAuthorizationStatusAuthorized");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case PHAuthorizationStatusDenied:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@"PHAuthorizationStatusDenied");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case PHAuthorizationStatusNotDetermined:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@"PHAuthorizationStatusNotDetermined");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case PHAuthorizationStatusRestricted:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@"PHAuthorizationStatusRestricted");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; }}];我相信有人可以告诉您如何在Swift中执行相同的操作。
打开App,查看更多内容
随时随地看视频慕课网APP