本文介绍了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=查询已取消}
我的代码包含在下面:
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.
- 首先我们需要调用这个方法进行授权
授权码
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
的正确方法调用方式
- Correct way of method Calling of
didFinishPickingMediaWithInfo
错误:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!