2

My objective-c code is erroring out with the Code=13 error, and does not display either the cameras photo or a library's image in an image view.

I'M Using Xcode 10.1, deployment target 12.0, and I'm going off example from UIImagePickerController not picking image in iOS 9

I have two problems:

1) Even though I add in "Privacy - Photo Library Usage Description | We want to use the library" in the p-list, it still gives me this error:

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

What am I doing wrong?

2) I can't get the image to show up in the LoveImage view. What am I doing wrong here?

Below is .m file:

-(IBAction)imagepickertapped:(id)sender { 
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Attach image" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* pickFromGallery = [UIAlertAction actionWithTitle:@"Take a photo"
                                                          style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction * action) {
                                                            if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                                                            {
                                                                UIImagePickerController* picker = [[UIImagePickerController alloc] init];
                                                                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                                                                picker.delegate = self;
                                                                [self presentViewController:picker animated:YES completion:NULL];
                                                            }

                                                        }];
UIAlertAction* takeAPicture = [UIAlertAction actionWithTitle:@"Choose from gallery"
style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action) {
                                                         UIImagePickerController* picker = [[UIImagePickerController alloc] init];
                                                         picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                                                         picker.delegate = self;
                                                         [self presentViewController:picker animated:YES completion:NULL];
                                                     }];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel"
                                         style:UIAlertActionStyleCancel
                                               handler:^(UIAlertAction * action) {
                                               }];

[alertController addAction:pickFromGallery];
[alertController addAction:takeAPicture];
[alertController addAction:cancel];
[self presentViewController:alertController animated:YES completion:nil]; }

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
UIImage *LoveImage = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
self.LoveImage = info[UIImagePickerControllerOriginalImage];}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
EvanS
  • 21
  • 1
  • For the "Code 13" error, have you checked this? [PhotoPicker discovery error: Error Domain=PlugInKit Code=13](https://stackoverflow.com/q/44465904/2745495) – Gino Mempin Jan 15 '19 at 01:28
  • 1
    Please [review these search results](https://stackoverflow.com/search?q=errors+encountered+while+discovering+extensions%3A+Error+Domain%3DPlugInKit+Code%3D13). Always search on an error before posting. – rmaddy Jan 15 '19 at 03:12
  • @Evans have you got your answer? – Sagar koyani Jan 16 '19 at 04:09
  • @Sagarkoyani - I'm almost there. The code from rmaddy works great! However, it is still giving me the Code=13 error. The answers I find are written in Swift - do you have a Objective C solution? I believe I need to somehow ask for permission from the user based off the plist privacy. I entered in: Privacy - Photo Library Additions Usage Description | We want to use the library and Privacy - Camera Usage Description | We want to use the Camera. I assumed it would pop up. How do I ask that to the user? – EvanS Jan 18 '19 at 21:52

1 Answers1

1

Change your didfinish method code to below.

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    UIImage *LoveImage = info[UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];
    self.LoveImage.image = LoveImage;
}

LoveImage is an image view. We can't assign an image to it directly. It has an image property so we have to set its image property.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sagar koyani
  • 403
  • 2
  • 12