Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIImagePickerController适用于iOS 11.1,但不适用于iOS 11.4_Ios_Camera_Uiimagepickercontroller_Photolibrary - Fatal编程技术网

UIImagePickerController适用于iOS 11.1,但不适用于iOS 11.4

UIImagePickerController适用于iOS 11.1,但不适用于iOS 11.4,ios,camera,uiimagepickercontroller,photolibrary,Ios,Camera,Uiimagepickercontroller,Photolibrary,我有一套相当典型的控件来拍照或从用户的照片库中进行选择。我在Xcode中使用的最新操作系统版本是11.1,图像选择器使用我使用的代码。(我不知道是否有可能在模拟器上运行新版本。) 当我在实际的iPhone(iOS 11.4的5s)上运行代码时,我从图像选择器中得到一个发现错误: 错误域=PlugInKit Code=13“查询已取消”UserInfo={NSLocalizedDescription=query cancelled} 尝试使用相机只会导致返回视图控制器,显然没有对新图像数据采取任何

我有一套相当典型的控件来拍照或从用户的照片库中进行选择。我在Xcode中使用的最新操作系统版本是11.1,图像选择器使用我使用的代码。(我不知道是否有可能在模拟器上运行新版本。)

当我在实际的iPhone(iOS 11.4的5s)上运行代码时,我从图像选择器中得到一个发现错误:

错误域=PlugInKit Code=13“查询已取消”UserInfo={NSLocalizedDescription=query cancelled}

尝试使用相机只会导致返回视图控制器,显然没有对新图像数据采取任何操作,也没有错误消息

编辑:我拥有info.plist的照相机和照片库权限,但它们似乎不会影响此问题

以下是相关代码(VC做了其他一些不相关的事情):

UserProfileViewController.h

#import <UIKit/UIKit.h>

@interface UserProfileViewController : UIViewController <NSURLSessionDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIScrollViewDelegate>
{
    __weak IBOutlet UIScrollView *scrolview;

}

@end

事实证明,该图像实际上是在uploadPhoto功能中更新的,但直到应用程序被销毁并重新启动后才显示

显然,这种效果是在dismissViewController的完成块中进行的图像处理造成的,而不是在didFinishPickingMediaWithInfo的主块中。将完成块设置为NULL并移动缩放和上载代码修复了该问题

#import "UserProfileViewController.h"

. . . 

- (IBAction)takePhoto:(id)sender {

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    UIAlertController *errAlertController = [UIAlertController alertControllerWithTitle:@"Whoa!" message:@"This phone doesn't have a camera." preferredStyle:UIAlertControllerStyleAlert];
    [errAlertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:errAlertController animated:YES completion:nil];
}
else
{

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

[self presentViewController:picker animated:YES completion:NULL];

    }
}

- (IBAction)ChooseFromGallery:(id)sender {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:picker animated:YES completion:NULL];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {


[picker dismissViewControllerAnimated:YES completion:^{
    UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];

    if ((chosenImage.size.height > 600.0) || (chosenImage.size.width > 800.0)){  // Need to scale down?
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(800.0f, 600.0f), NO, 0.0);
        [chosenImage drawInRect:CGRectMake(0, 0, 800, 600)];
        UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        [self uploadPhoto:scaledImage];
    }
    else {
        [self uploadPhoto:chosenImage];
    }
    // "uploadPhoto" takes the JPG representation of the image and uploads it to a specific server path using HTTP POST. As mentioned, it worked in the simulator for iOS 11.1.
    }];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

[picker dismissViewControllerAnimated:YES completion:NULL];

}