与
相似PhotoPicker discovery error: Error Domain=PlugInKit Code=13
还有
https://forums.developer.apple.com/thread/82105
但是我已经尝试了所有这些建议,但仍然在调试日志中出错。运行 Swift 4 XCode 9A235
各个地方的建议是......
我没有在Swift 3中遇到这个问题 - 以前的xcode。 但是使用Swift 4,我尝试了每次看到的建议,但仍然会出现以下错误
发现扩展时遇到[发现]错误:错误域= PlugInKit代码= 13"查询已取消" UserInfo = {NSLocalizedDescription =查询已取消}
选择器工作正常,我最终选择了照片中的图像,但每次都在选择器出口(取消或选择)上收到此错误消息...
有关如何停止错误消息的任何建议吗?除了其他两个链接提供的事项列表(上文概述)
我的方法
@objc internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
imageSelected = nil
if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage {
imageSelected = editedImage
} else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
imageSelected = originalImage
}
if imageSelected != nil {
handleSelectedImage() // override in subclass to do something with the returned image
}
picker.dismiss(animated: true, completion: nil) // mess of calling both dismiss to see if it helps - it does not
dismiss(animated: true, completion: nil)
}
答案 0 :(得分:15)
见mc-system-group-container-and-mc-reading-from-public-effective-user-settings-err
对我来说工作很好
如果它可以帮助我的代码(使用xcode 9)
if libraryAuthorization == .authorized {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.allowsEditing = false
imagePicker.view.tag = button.tag
self.present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickerImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
photoContainer.addImageToButton(pickerImage, buttonTag: picker.view.tag)
dismiss(animated: true)
}
}
答案 1 :(得分:2)
我遇到了同样的问题并尝试了我能找到的所有解决方案,但没有任何帮助。刚问自己,代表未被触发会发生什么:代表的解除分配!
这就是我的情况!在呈现UIImagePickerController时我的class ImagePickerController : NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate
实例
这不是呈现视图控制器,将直接解除分配。当然代理功能不能再执行了。
只需在deinit
(或Objective-C世界中的dealloc
)中放置一个断点,然后查看您的代理是否已被解除分配。
答案 2 :(得分:2)
用户问:“*有关如何停止错误消息的任何建议吗?除了其他两个链接(上面概述的)提供的事项列表之外”。
我使用了两个步骤来消除错误消息。 感谢Antoine Richeux https://stackoverflow.com/users/5767821/antoine-richeux以上的人 我认为pList中的隐私添加可能没有必要,至少在我的情况下
第1步。 从菜单栏中选择:产品>方案>编辑方案> 从Build,Run ... Archive的左侧列表中选择Run 从右侧的顶部选择集中选择Arguments - 参见附图。 使用“环境变量”下的+按钮添加新条目 名称:OS_ACTIVITY_MODE 值:禁用
This shows where to add the environment variable
第2步。 清理项目并重建
答案 3 :(得分:2)
对于Swift 4:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else {
return
}
...
}
[String: Any]
更改为[UIImagePickerController.InfoKey : Any]
info["UIImagePickerControllerOriginalImage"]
更改为info[UIImagePickerController.InfoKey.originalImage]
答案 4 :(得分:1)
这是因为您的应用使用照片库(在这种情况下,使用UIImagePickerController
)而不需要用户权限。例如,如果我想点击添加按钮时显示图像选择器:
@IBAction func addButtonTapped(_ sender: UIBarButtonItem) {
checkPermission {
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
picker.delegate = self
picker.allowsEditing = false
self.present(picker, animated: true, completion: nil)
}
}
func checkPermission(hanler: @escaping () -> Void) {
let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
switch photoAuthorizationStatus {
case .authorized:
// Access is already granted by user
hanler()
case .notDetermined:
PHPhotoLibrary.requestAuthorization { (newStatus) in
if newStatus == PHAuthorizationStatus.authorized {
// Access is granted by user
hanler()
}
}
default:
print("Error: no access to photo album.")
}
}
此外,还需要将此添加到您的plist:
<key>NSPhotoLibraryUsageDescription</key>
<string>So that you can add images for your cloth. </string>
这是权限对话框中显示的消息。
答案 5 :(得分:1)
你可以尝试一下吗?
extension YourProfileViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
log.debug("Called imagePickerController function ")
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true) {
self.yourProfileImageView.image = image
}
}
}
答案 6 :(得分:1)
我也遇到了这个问题。这很烦人,因为出现控制台错误,但应用程序仍在加载图像。我请求授权状态,将我的密钥添加到.plst,但没有找到任何一项可以完成工作。
一旦我进入产品->方案->编辑方案->运行,然后添加了密钥:“ OS_ACTIVITY_MODE ”值:“ 禁用 ”,清理并重建...错误消失了。
答案 7 :(得分:0)
请务必声明您的班级实施UINavigationControllerDelegate
。
extension MyViewController: UINavigationControllerDelegate {}
出于某种原因,在Xcode 9.0中,它警告我如此声明委托:
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
答案 8 :(得分:0)
在 Swift 4.2 和 Xcode 10.0 上发生了相同的问题。尽管图像选择器工作正常,但Xcode在控制台上显示了此错误。要摆脱这种情况:
答案 9 :(得分:0)
reqId
您需要获取var messageImage = UIImage()
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
self.dismiss(animated: true, completion: { () -> Void in
})
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
{
messageImage = image
}
print("Image Captured")
}
而不是UIImagePickerController.InfoKey.originalImage