可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Similar to
PhotoPicker discovery error: Error Domain=PlugInKit Code=13
and also to
https://forums.developer.apple.com/thread/82105
BUT I have tried all of these suggestions and still get an error in the debug log. Running Swift 4 XCode 9A235
What was suggest at the various places was ...
- some people said add @objc
- some people said add internal
- some people suggested adding _ and making sure using Any and not
AnyObject
- some people said to use didFinishPickingImageWithInfo (this returns
no image for me)
- some people said dismsss the picker, others said dismiss self, others
said dismiss both
- some said add the 'Privacy... ' to plist (done)
- added import Photos
- added prior call to force PHPhotoLibrary.requestAuthorization() {
(status) -> Void in ...
I DID NOT get this issues in Swift 3 - previous xcode.
But with Swift 4, I tried everying I saw suggested and I still get the following error
[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
The picker works fine and I DO end up selecting an image from photos, but I get this error message on picker exit (cancel or select), every time...
Any suggestions how to stop the error message? Other than the list of things offered at the other two links (summarized above)
my method
@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)
}
回答1:
- add the 'Privacy... ' to plist
- From Xcode menu open: Product > Scheme > Edit Scheme >
On your Environment Variables set OS_ACTIVITY_MODE in the value set disable
see in mc-system-group-container-and-mc-reading-from-public-effective-user-settings-err
Work's fine for me
EDIT
if it's can help below my code (working with 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)
}
}
回答2:
I had the same issue and tried every solution I could find, but nothing helped. Just asked myself what could happen to the delegate to not being triggered: deallocation of the delegate!
And that was it in my case! When presenting the UIImagePickerController my instance of class ImagePickerController : NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate
which isn't the presenting view controller, will be deallocated directly. Of course the delegate functions can't be executed anymore.
Just put a breakpoint in deinit
(or dealloc
in Objective-C world) and see if your delegate is being deallocated.
回答3:
The user asks: "*Any suggestions how to stop the error message? Other than the list of things offered at the other two links (summarized above)".
I used two steps to eliminate the error message.
Kudos to the person above Antoine Richeux https://stackoverflow.com/users/5767821/antoine-richeux.
I think the Privacy addition to pList may not be necessary, at least in my case
STEP 1.
From the Menu bar select: Product > Scheme > Edit Scheme >
select Run from the left side list of Build, Run ... Archive
Select Arguments from top set of selections on right side - see picture attached.
Use the + button under Environment Variables to add a new entry
Name: OS_ACTIVITY_MODE
Value: disable
This shows where to add the environment variable
STEP 2.
Clean the project and rebuild
回答4:
It is because your app uses photo library (in this case, using UIImagePickerController
) without asking for user permission. As an example, if I want to show the image picker when the add button was tapped:
@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.")
}
}
In addition, need to add this to your plist as well:
<key>NSPhotoLibraryUsageDescription</key>
<string>So that you can add images for your cloth. </string>
which is the message displayed in the permission dialog.
回答5:
Can you try it out ?
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:
I also had this issue. It's very annoying because the console error comes up but the app is still loading the image. I requested authorization status, added my keys to the .plst, but found none of this to get the job done.
Once I went to Product -> Scheme -> Edit Scheme -> Run then added key: "OS_ACTIVITY_MODE" value: "disable", cleaned and rebuilt...the error went away.
回答7:
For Swift 4:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else {
return
}
...
}
- On method parameter, change from
[String: Any]
to [UIImagePickerController.InfoKey : Any]
- On the picked image, change from
info["UIImagePickerControllerOriginalImage"]
to info[UIImagePickerController.InfoKey.originalImage]
回答8:
Make sure you declare that your class implements UINavigationControllerDelegate
.
extension MyViewController: UINavigationControllerDelegate {}
For some reason in Xcode 9.0 it warned me to declare the delegate as such:
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
回答9:
Had this same issue on Swift 4.2 and Xcode 10.0. Although the image picker was working correctly Xcode showed this error on console. To get rid of this:
- On Xcode menu Product > Scheme > Edit Scheme
- Select 'Run' tab, then 'Arguments'
- On 'Environment Variables' section add a variable with Name OS_ACTIVITY_MODE and Value disable