调用相册报(Error Domain=PlugInKit Code=13 "query cancelled" )

调用相册是使用频率很高的一个功能,之前没遇到过这种问题,所有代码从逻辑上都是合理的,但是就是获取不到图片,一直打印报错:

[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

反复调试代码,最终在Stack Overflow上找到相关资料https://stackoverflow.com/questions/44465904/photopicker-discovery-error-error-domain-pluginkit-code-13,解决了不能拿到Image问题,但是还会打印错误信息,不影响功能使用,但是还是不懂为什么会提示这个错误。

下面是我的代码:.h文件

#import <Foundation/Foundation.h>

@interface HS_ImagePicker : NSObject

- (void)HS_pickWithTarget:(UIViewController*)target completionHandler:(void(^)(UIImage*))completion;

@end

.m文件

#import "HS_ImagePicker.h"
@interface HS_ImagePicker()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>

@property (nonatomic,weak) UIViewController *target;

@property (nonatomic,copy) void (^completionHandler)(UIImage* image);

@end

@implementation HS_ImagePicker

- (void)HS_pickWithTarget:(UIViewController *)target completionHandler:(void (^)(UIImage *))completion {
    
    self.target = target;
    
    self.completionHandler = completion;
    
    UIAlertController *alert = [[UIAlertController alloc] init];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *album = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            [self pickerWithType:UIImagePickerControllerSourceTypePhotoLibrary];
        }
    }];
    
    UIAlertAction *photo = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            [self pickerWithType:UIImagePickerControllerSourceTypeCamera];
        }
    }];
    
    [alert addAction:cancel];
    [alert addAction:album];
    [alert addAction:photo];
    
    [target presentViewController:alert animated:YES completion:nil];
}

- (void)pickerWithType:(UIImagePickerControllerSourceType)sourceType {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = sourceType;
    picker.allowsEditing = YES;
    [_target presentViewController:picker animated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    [picker dismissViewControllerAnimated:YES completion:^{
        if (self.completionHandler) {
            self.completionHandler(info[UIImagePickerControllerEditedImage]);
        }
    }];
}

@end

调用代码:

1、不能正常获取Image图片

- (void)viewDidLoad {
    [super viewDidLoad];

    HS_ImagePicker* view = [[HS_ImagePicker alloc] init];
    [view HS_pickWithTarget:self completionHandler:^(UIImage *image) {
        NSLog(@"%@",image);
    }];
}

错误信息:

[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

2、可以正常获取Image图片,但是还会打印错误信息

//声明属性
@property (nonatomic,strong) HS_ImagePicker *picker;
- (void)viewDidLoad {
    [super viewDidLoad];
    //调用
    [self picker];
}
//懒加载
- (HS_ImagePicker *)picker {
    if (!_picker) {
        _picker = [[HS_ImagePicker alloc] init];
        [_picker HS_pickWithTarget:self completionHandler:^(UIImage *image) {
            NSLog(@"%@",image);
        }];
    }
    return _picker;
}

打印信息:

//错误信息
[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
//打印的Image
<UIImage: 0x6040002bb120> size {1125, 744} orientation 0 scale 1.000000

info里面也设置了获取权限的key,还是会打印这个信息。

有遇到过的大佬给指导下╮(╯_╰)╭

posted on 2018-06-22 11:41  大~🐻~熊  阅读(8548)  评论(1编辑  收藏  举报

导航