Search code examples
iosobjective-cuiimagepickercontrollerios10

How can I access a user's Camera/Photos library in a Messages Extension?


I'm making an iOS Messages Extension Application that should be able to upload a picture either taken from the camera roll or selected from a user's photo library to use in the app (my extension is just a simple way to add a filter to the image before sending it).

I added the Photos and Camera permission in info.plist, but I'm still getting a crash.

info.plist

I know this is faulty code (mainly written for quick development/testing), but it's still crashing. Does anyone know why?

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
    NSLog(@"AVAILABLE");
}
else {
    NSLog(@"ERROR HERE");
    return;
}

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];

With this error message

2017-02-18 23:39:33.318 MessagesExtension[34704:3560916] Failed to inherit CoreMedia permissions from 34702: (null) 2017-02-18 23:39:35.585 MessagesExtension[34704:3560818] CHOOSE PHOTO 2017-02-18 23:39:35.585 MessagesExtension[34704:3560818] AVAILABLE (lldb)

enter image description here


Solution

  • Figured it out!!

    There are two Info.plists that I needed to add Camera/Photo Library permissions to: one for the Extension and one for the Application.

    I had only added the Camera/Photo Library permissions key to one Info.plist when I should have added it to both