I have a fairly typical set of controls to take a picture or choose from a user's photo library. The latest OS version I have in Xcode is 11.1, and the image picker works with the code I have. (I don't know whether it's possible to run a newer version on the simulator yet.)
When I run the code on an actual iPhone (5s with iOS 11.4), I get a discovery error from the image picker:
Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
Trying to use the camera simply results in returning to the view controller, apparently with no action taken on the new image data, and no error messages.
EDIT: I have camera and photo library permissions to the info.plist, but they don't seem to affect this issue.
Here's the relevant code (the VC does several other unrelated things):
UserProfileViewController.h
#import <UIKit/UIKit.h>
@interface UserProfileViewController : UIViewController <NSURLSessionDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIScrollViewDelegate>
{
__weak IBOutlet UIScrollView *scrolview;
}
@end
UserProfileViewController.m:
#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];
}