我正在尝试在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)
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
字典值在obj-c中被转换为id。我还实现了访问用户照片库的授权请求和处理:仍然收到错误消息。我在info.plist文件中添加了隐私条目供用户的照片库使用。