PhotoPicker 发现错误:错误域 = PlugInKit 代码 = 13

Posted

技术标签:

【中文标题】PhotoPicker 发现错误:错误域 = PlugInKit 代码 = 13【英文标题】:PhotoPicker discovery error: Error Domain=PlugInKit Code=13 【发布时间】:2017-11-11 22:48:38 【问题描述】:

我正在尝试在 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)
    

【问题讨论】:

我遇到了同样的错误。你在使用 Xcode 9 测试版、ios 11 吗? 这曾经可以工作......然后iOS 11 Beta 4突然给了我这个错误。太奇怪了。 我遇到了同样的错误,我的实现是在 obj-c 中。此错误消息与 Objective-c 中 UIImagePicker 委托方法中返回的信息字典的类型转换无关:- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info字典值在 obj-c 中被转换为 id。我还实现了访问用户照片库的授权请求和处理:仍然收到错误消息。我在 info.plist 文件中添加了用户照片库使用的隐私条目。 我收到了当前的错误,但这并不妨碍我从库中获取图像并在以后使用它.. 我尝试了 all 中的 all 的建议组合,但无济于事。 【参考方案1】:

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

【讨论】:

为我工作。我最近更新到 Swift 4 和 Xcode 9,这解决了它。 为我工作。迁移到 Swift 4.0 后需要。 不起作用。这个错误发生在我打电话给dismiss之后。 奇怪。这对我有用,但是 xcode 将其标记为警告并期望签名:` Instance method 'imagePickerController(:didFinishPickingMediaWithInfo:)' 几乎与协议的可选要求 'imagePickerController(:didFinishPickingMediaWithInfo:)' 匹配' UIImagePickerControllerDelegate' 将 'imagePickerController(_:didFinishPickingMediaWithInfo:)' 设为私有以消除此警告 ` @DarkCastle 您需要将函数写入类外部的extension [your class name] 块中。【参考方案2】:

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

    首先我们需要调用这个方法进行授权

授权码

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

我希望此解决方案能帮助您解决此错误。

如果它对您有用,请不要忘记将其标记为正确,因此这将有助于其他人找到正确的方法。

【讨论】:

Noob PSA:PHPhotoLibrary 来自 Swift 的照片模块 不起作用。错误发生在我调用picker.dismiss(animated: true, completion: nil)【参考方案3】:

我找到了!它试图告诉您您没有“照片”的授权您需要包含 #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;
    
];

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

【讨论】:

一定要包含#import 这并没有解决我的问题。 我在控制台中收到以下消息“从私人有效用户设置中读取。发现扩展时遇到的错误:错误域 = 插件代码 = 13“查询已取消”用户信息 = NSLocalizedDescription = 查询已取消“ .它没有解决问题。【参考方案4】:

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

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

Error Domain=PlugInKit Code=13 "查询已取消" UserInfo=NSLocalizedDescription=query cancelled"

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

1) UIImagePickerController 的委托是 (UIImagePickerControllerDelegate & UINavigationControllerDelegate)?,因此需要明确添加 UINavigationControllerDelegate 作为协议之一:

class ViewController:UIViewController, UIImagePickerControllerDelegate, 
    UINavigationControllerDelegate  .... . 

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

当然,你需要确保你创建了一个UIImagePickerController,并在ViewDidLoad()中设置它的代理等于self

class ViewController:UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate  
    let imagePickerController = UIImagePickerController()
    override func viewDidLoad() 
        super.viewDidLoad()
        imagePickerController.delegate = self
    
    ...

【讨论】:

我的项目中都有这一切.. 仍然无法正常工作 感谢我错过了在 viewDidLoad() 中设置委托【参考方案5】:

我已解决此问题,请在 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.")
        
    

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

【讨论】:

【参考方案6】:

XCODE 10.1 / SWIFT 4.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)
    
    

【讨论】:

在 Swift 4x 上使用 imagePickerController func 的真正方法【参考方案7】:

* Swift 3 中缺少 DELEGATE * 就我而言,所有设置都是正确的: 1 - 代表 (UIImagePickerControllerDelegate,UINavigationControllerDelegate); 2 - 权限已验证; 3 - Plist 已经完成; 4 - 我读到了这个答案的所有内容;

但我忘了在viewDidLoad 上实现pickerview.delegate = self 因为我从我的其他 viewController 复制和粘贴,然后忘记了!

我希望它对某人有所帮助,请先检查您的 COPY / PASTE!!!

【讨论】:

谢谢,苦苦挣扎了很长时间,我错过了“UINavigationControllerDelegate”,你终于保存了,谢谢 很高兴为您提供帮助:)【参考方案8】:

这可能不是最直接有用的答案 - 但希望它会有所帮助!我 99% 确信这个特定的错误消息实际上并没有指出真正的问题。我花了几个小时在同样的问题上拔头发。

1) 当我启动我的选择器时,我有权将照片打印到控制台,2) 我可以很容易地导航和选择一张照片,以及 3) 当我在关闭选择器后返回我的视图时,我的按钮图像没有用新照片更新...唯一提示我遇到的问题是您收到的错误消息完全相同。

原来我是在 ViewWillAppear 而不是 ViewDidLoad 中硬编码占位符图像。每次选择器关闭时,它都会调用 ViewWillAppear 并用我的硬编码图像替换我选择的图像。我解决了这个问题,果然 - 现在一切正常......每次我从选择器返回时,我仍然看到该错误消息。

我建议您在 ImagePicker 以外的地方寻找您的问题,您很可能会找到它。

【讨论】:

【参考方案9】:

如果您还没有这样做,请尝试this。

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

它解决了我的问题。

【讨论】:

这会抑制错误消息,但不会解决它们的原因。它还抑制其他系统消息和来自NSLog 的任何内容。 这并不能“解决”问题,只是使其不可见。非常糟糕的做法。 这相当于把你的污垢藏在地毯下【参考方案10】:

这解决了 Swift 4 中的问题:

更改下面的代码

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) 

到这里:

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


Swift 4.2 update:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])

【讨论】:

我的错误看起来像这样:发现扩展时遇到的错误:Error Domain=PlugInKit Code=13 "query cancelled" UserInfo=NSLocalizedDescription=query cancelled 这解决了我的问题,虽然我可以'如果这对 OP 有帮助,请不谈。谢谢:)【参考方案11】:

当我尝试从选取器回调 imagePickerController 中显示另一个控制器时,我收到了相同的消息。对我有用的解决方案是将我的代码从选择器关闭方法中移动到完成回调中

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)
            
        
    

【讨论】:

很好的答案,你节省了我的时间?? 工作出色!认为这是处理 Swift 4.x 中选择器错误的正确方法。【参考方案12】:

确保您对两者都进行了子类化:UIImagePickerControllerDelegate, UINavigationControllerDelegate

另外,记得设置委托:

let picker = UIImagePickerController()
picker.allowsEditing = true
picker.sourceType = .photoLibrary
picker.delegate = self  //Don't forget this line!
self.present(picker, animated: true, completion: nil)

感谢this source。

【讨论】:

picker.delegate = self — 是我的情况!谢谢。【参考方案13】:

找到解决这个问题的方法花了我很长时间。看起来问题是找不到 UIImagePickerControllerDelegate 的函数 imagePickerController 。如果您正确设置了委托,并且在升级到 Swift 4 后它停止工作,则问题可能是您没有使用自 Swift 4 以来必需的 @objc 使其对 Objective-C 可访问。

必须是:

@objc func imagePickerController(...

而不是

func imagePickerController(...

【讨论】:

创建错误Objective-C method 'imagePickerController:didFinishPickingMediaWithInfo:' provided by method 'imagePickerController(_:didFinishPickingMediaWithInfo:)' conflicts with optional requirement method 'imagePickerController(_:didFinishPickingMediaWithInfo:)' in protocol 'UIImagePickerControllerDelegate' 没错,这就是修复它的方法! @NicoNeill 您是否将函数添加到 extension 块中?【参考方案14】:

通过设置图像时设置1秒延迟来修复它。

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

    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage 

        picker.dismiss(animated: false, completion: nil)
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: 
            self.discussionImage.image = image
        )
    

【讨论】:

【参考方案15】:

请务必在开头添加internal func,然后在括号后添加小写(_ picker: UIImagePickerController…然后将AnyObject更改为Any]... 检查以下代码:

internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) 
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage 

        userPhoto.image = pickedImage

    

    self.dismiss(animated: true, completion: nil)

【讨论】:

【参考方案16】:

这让我很困惑,但下面链接中的答案对我有用。错误消失,图像按预期显示

就像上面的答案之一,您必须在函数之前有(_ picker...@objc

@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) 
...

https://forums.developer.apple.com/thread/82105

【讨论】:

【参考方案17】:

这解决了我的错误:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) 
    let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
    addPhotoBtn.setImage(pickedImage, for: .normal)
    dismiss(animated: true, completion: nil)




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


【讨论】:

【参考方案18】:

请按以下步骤检查:

    导入照片

    可以访问相册:

    func authorizeToAlbum(completion:@escaping (Bool)->Void) 
    
    if PHPhotoLibrary.authorizationStatus() != .authorized 
        NSLog("Will request authorization")
        PHPhotoLibrary.requestAuthorization( (status) in
            if status == .authorized 
                DispatchQueue.main.async(execute: 
                    completion(true)
                )
             else 
                DispatchQueue.main.async(execute: 
                    completion(false)
                )
            
        )
    
     else 
        DispatchQueue.main.async(execute: 
            completion(true)
        )
    
    
    

    呈现 UIImagePickerController

    self.authorizeToAlbum  (authorized) in
        if authorized == true 
            let picker = UIImagePickerController()
            picker.delegate = self
            picker.allowsEditing = false
            picker.sourceType = .photoLibrary
    
            self.present(picker, animated: true, completion: nil)
        
    
    

    关键步骤,确保委托方法严格遵循

    // MARK: - UIImagePickerControllerDelegate Methods
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) 
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage 
        self.pickedImage = pickedImage
        if let finalImage = handleImage(originalImage: self.pickedImage!, maskImage: self.maskImage!) 
            self.imageView.image = finalImage
        
    
    
    dismiss(animated: true, completion: nil)
    
    

【讨论】:

【参考方案19】:

这就是我所做的,它解决了我的问题。

添加@objc 添加内部 在imagePicker前添加_ 确保您使用的是 Any 而不是 AnyObject

希望这会有所帮助!

【讨论】:

嗯,internal 是默认值;我想知道指定它有什么不同...【参考方案20】:

在我的情况下,我收到了这个错误,因为我在没有首先验证用户是否允许访问图像的情况下展示了一个图像选择器控制器。在我的代码的其他地方,用户已授予权限,所以我认为我需要做的就是导入照片。但是,由于他们“可能”没有在应用程序中授予权限,因此在我展示图像选择器控制器为我解决问题之前添加了此权限(也可以导入照片)。

// request photos permission if permission has not been granted
    if PHPhotoLibrary.authorizationStatus() != PHAuthorizationStatus.authorized 
        PHPhotoLibrary.requestAuthorization( (status: PHAuthorizationStatus) in

        )
    

如果这个答案看起来多余,我很抱歉,但我必须从几个不同的答案中拼凑起来才能让我的解决方案发挥作用。也许这会帮助其他使用 Swift 4 的人。

【讨论】:

【参考方案21】:

使用此代码

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])

【讨论】:

【参考方案22】:

这个“Error Domain=PlugInKit Code=13”错误让很多人感到困惑,尽管它似乎是一个无害的苹果调试消息。我在获取我选择在 UI 中设置的图像时遇到问题,并认为该错误是问题所在,但它有点微妙。

我的图像选择器控制器与呈现它的视图控制器分开的文件中。

MyViewController.swift

class MyViewController: UIViewController 
    @IBOutlet weak var profileImage: UIImageView!

    ...


extension MyViewController: ImagePickerDelegate 
    func didSelect(image: UIImage?) 
        self.profileImage.image = image
    

ImagePicker.swift

open class ImagePicker: NSObject 
    ...
    private func pickerController(_ controller: UIImagePickerController, didSelect image: UIImage?) 
        controller.dismiss(animated: true, completion: self.delegate?.didSelect(image: image)
        )
    

大多数教程和答案都将完成设置为 nil。但是,如果您将完成设置为 nil 并单独调用委托的 didSelect 方法,则该方法会被调用但图像未设置,因此请确保使用关闭完成。

再一次,我知道这个答案可能与最初的问题没有直接关系,但我感觉很多人都是为了这个问题来到这里的,而给定的解决方案并没有帮助。原因是大多数给出答案的人都将他们的图像选择器控制器与他们的主视图控制器在同一个类中,因此不需要使用完成。

【讨论】:

这正是我所需要的。谢谢!【参考方案23】:

如果您在Info.plist 文件中没有配置照片库的使用权限,也会发生此错误。

您需要在Info.plist 中添加Privacy - Photo Library Usage Description,并在您的应用第一次尝试访问用户的照片库时显示一个字符串

最终的Info.plist 调整应如下所示:

【讨论】:

【参考方案24】:

我有同样的错误,我用这种方式修复了它:

获取图像对象的不同方式取决于 UIImagePickerController 允许编辑是真还是假

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

    if isImagePickerAllowEditing 
        sourceImage = info[UIImagePickerControllerEditedImage] as? UIImage
     else 
        sourceImage = info[UIImagePickerControllerOriginalImage] as? UIImage
    

    ....


当然,如上面的cmets一样,首先请求访问照片库的权限。

【讨论】:

【参考方案25】:

我的 UINavigationControllerDelegate 代表不见了。

class YourViewController:UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate

【讨论】:

【参考方案26】:

在我的情况下,Apple Team 似乎优化并修复了快速分配内存管理。 我的代码在快速更新之前运行良好,我发现我的“错误”是我没有保留选择器,但它已经工作了很长时间而没有保留,所以这里有一个完整的准备工作解决方案。

// Add Privacy - Photo Library Usage Description to your info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string>APPNAME need to access your pictures to violate your privacy :P</string>

import Photos    
class MyImageSelector: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate 

    var picker = UIImagePickerController() 
    // Make sure to retain this picker var until the picker returned

    func checkPermission() 
        let call = self.presentAuthorized

            let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
            switch photoAuthorizationStatus 
            case .authorized:
                print("Access is granted by user")
                showPicker()
            case .notDetermined:
                PHPhotoLibrary.requestAuthorization( newStatus in
                print("status is \(newStatus)")
                if newStatus == PHAuthorizationStatus.authorized 
                    /* do stuff here */
                    print("success")
                    showPicker()
                
                )
            case .restricted:
                print("User do not have access to photo album.")
            case .denied:
                print("User has denied the permission.")
            

    

    func showPicker() 
        picker = UIImagePickerController()
        picker.allowsEditing = true
        picker.sourceType = .photoLibrary
        picker.delegate = self  //Don't forget this line!
        self.present(picker, animated: true, completion: nil)
    

    @objc public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) 
        // DO something with picture
    

    @objc public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) 
        // User cancelled the pick
    

【讨论】:

【参考方案27】:

我遇到了同样的问题。上述建议都不适合我。但是,我通过显式调用 picker.dismiss 并关闭该帖子来解决它。我不清楚为什么我会发出这样的解雇电话,但它对我有用。

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

        print("Image picked")
        picker.dismiss(animated: true, completion: nil)
        dismiss(animated: true) 
            print("dismissed")
             self.delegate?.presentEditor(img: (info[UIImagePickerControllerOriginalImage] as? UIImage)!, id: self.id!)
    


【讨论】:

【参考方案28】:

我阅读了所有这些答案并在此处稍作修改,无需关闭,这对我有用,感谢其他在这里回复的人。

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

      print("########### media picked")
      picker.dismiss(animated: true, completion: nil)
      let img = (info[UIImagePickerControllerOriginalImage] as? UIImage)!
      //set img -picked image to "profileImage" UIimageView
      //use image here
       self.profileImage.image = img
       
    

【讨论】:

【参考方案29】:

我找到了IMage PickerView的解决方案.....

@IBOutlet weak var myImageView: UIImageView!

var imagePicker = UIImagePickerController()


  @IBAction func selectImage(_ sender: Any) 

        let myPickerController = UIImagePickerController()
        myPickerController.delegate = self;
        myPickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary

        self.present(myPickerController, animated: true, completion: nil)

    

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

        var selectedImageFromPicker: UIImage?

        if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage
        
            selectedImageFromPicker = editedImage as! UIImage


        else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage

            selectedImageFromPicker = originalImage as! UIImage


        

        dismiss(animated: true, completion: nil)

        if var selectedImage = selectedImageFromPicker
        
            myImageView.image = selectedImage
        

    

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

【讨论】:

【参考方案30】:

单击 imageView 以从照片库加载图像并在同一 imageview 上显示预览。斯威夫特 4

 let imagePicker = UIImagePickerController()
        @IBOutlet weak var userImage: UIImageView! 

     override func viewDidLoad() 
                super.viewDidLoad()
                 imagePicker.delegate = self
                let tap = UITapGestureRecognizer(target: self, action: #selector(SignUpViewController.click))
                userImage.addGestureRecognizer(tap)
                userImage.isUserInteractionEnabled = true
            

            @objc func click()
            
                imagePicker.allowsEditing = false
                imagePicker.sourceType = .photoLibrary
                present(imagePicker, animated: true, completion: nil)
            


            @objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) 
                if  let chosenImage = info[UIImagePickerControllerOriginalImage] as? UIImage
                userImage.contentMode = .scaleAspectFit
                userImage.image = chosenImage
                
                dismiss(animated: true, completion: nil)
            

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

【讨论】:

以上是关于PhotoPicker 发现错误:错误域 = PlugInKit 代码 = 13的主要内容,如果未能解决你的问题,请参考以下文章

在 PL/SQL 脚本上使用 DB 链接会引发“找不到表”错误

将 UIImage 从 photopicker 传递到以前的 ViewController

iOS PhotoPicker 示例在 4.0 模拟器下崩溃

PL/pgSQL 中的“格式错误的数组文字”错误

PL\SQL 语句忽略错误

ORACLE:错误错误(6,3):PL/SQL:SQL 语句被忽略和错误(8,3):PL/SQL:ORA-00933:SQL 命令未在过程中正确结束