調用相冊報(Error Domain=PlugInKit Code=13 "query cancelled" )

調用相冊是使用頻率很高的一個功能,以前沒遇到過這種問題,全部代碼從邏輯上都是合理的,可是就是獲取不到圖片,一直打印報錯:dom

[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問題,可是還會打印錯誤信息,不影響功能使用,可是仍是不懂爲何會提示這個錯誤。atom

下面是個人代碼:.h文件spa

#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

調用代碼:code

一、不能正常獲取Image圖片blog

- (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}

二、能夠正常獲取Image圖片,可是還會打印錯誤信息ip

//聲明屬性
@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;
}

打印信息:get

//錯誤信息
[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,仍是會打印這個信息。it

有遇到過的大佬給指導下╮(╯_╰)╭

相關文章
相關標籤/搜索