【问题标题】:Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled} with Objective C Xcode 9.3 iOS 11错误域 = PlugInKit 代码 = 13 "查询已取消" UserInfo = {NSLocalizedDescription = 查询已取消} 与 Objective C Xcode 9.3 iOS 11
【发布时间】:2019-02-11 15:59:08
【问题描述】:

我正在使用UIImagePickerController 从设备获取图像。我已经实施了以下步骤:

  1. 获得许可: 隐私 - 照片库使用说明 - info.plist
  2. 创建并呈现 UIImagePickerController 的实例。代表被分配给自己。相机或库选项由 UIAlertController 提供。

    -(void) openGallery {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
    
        UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
        [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        }]];
    
        [actionSheet addAction:[UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            // take photo button tapped.
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:picker animated:YES completion:NULL];
        }]];
    
        [actionSheet addAction:[UIAlertAction actionWithTitle:@"Photo Library" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            // PhotoLibrary
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentViewController:picker animated:YES completion:NULL];
        }]];
    
        [self presentViewController:actionSheet animated:YES completion:nil];
    }
    
  3. 在委托上,图像已到达,但是当我将其转换为 base64 后尝试将其上传到服务器时,AFNetworking 抛出错误:

    错误域=PlugInKit 代码=13 "查询已取消" UserInfo={NSLocalizedDescription=查询已取消} 使用 Objective C Xcode 9.3 iOS 11

    #pragma mark- UIImagePicker Delegate
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
        UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    
        [picker dismissViewControllerAnimated:YES completion:NULL];
    
        [self.view setUserInteractionEnabled:NO];
        [self uploadThemeServiceCall: chosenImage];
    }
    

我尝试创建 OS_ACTIVITY_MODE 以在环境变量中禁用,但它不起作用。我尝试了其他可用的解决方案,但仍然无法正常工作。它工作正常,但现在不行了。

【问题讨论】:

    标签: ios objective-c uiimagepickercontroller


    【解决方案1】:

    A:) 确保对象 selectedImage 不为零。 B :) 使用 NSData *imageData = UIImageJPEGRepresentation(imageObject , 1)chosenImage 转换为 NSData 。将此 imageData 用作您的 NSUrlRequest 正文。

    请在此处显示函数uploadThemeServiceCall 的代码。

    【讨论】:

    • 感谢您的建议。图片不为零。
    • 你是否使用 NSData *imageData = UIImageJPEGRepresentation(imageObject , 1) 来获取 nsdata 中的图像?
    • 这是您在 AFNetworking 3.0 中发出帖子请求的方式 -
    • AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; NSDictionary *params = @{@"user[height]": height, @"user[weight]": weight}; [manager POST:@"example.com/myobject" 参数:params 进度:nil 成功:^(NSURLSessionTask *task, id responseObject) { NSLog(@"JSON: %@", responseObject); } 失败:^(NSURLSessionTask *operation, NSError *error) { NSLog(@"Error: %@", error); }];
    • 对我来说,didFinishPickingMediaWithInfo 甚至没有被调用。问题解决了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 2017-03-19
    • 2021-07-30
    • 2017-11-11
    • 1970-01-01
    相关资源
    最近更新 更多