Brittany Brittany - 6 months ago 59
Objective-C Question

Activating camera crashes my app?

Strange issue:

My users activate the iPhone camera by tapping a button to take a photo. E.g. button is tapped, camera opens. Up until yesterday, the code below worked completely fine (and still does on my own phone). However, on everyone else's phone in our test group, the app crashes as soon as the camera button is tapped. Any idea as to why? See my code below - I'm stumped. Note: Everyone is running iOS 10.


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextFieldDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> {


@property (strong, nonatomic) NSMutableArray *photoData;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;



- (IBAction)takePhoto:(id)sender {

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

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


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

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;

[picker dismissViewControllerAnimated:YES completion:NULL];


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

[picker dismissViewControllerAnimated:YES completion:NULL];



If it is crashing only on ios10 then it may be the problem of privacy key setting which is mandatory in ios10 and xcode 8. so you need to add below key,

  Privacy - Photo Library Usage Description

to in your info.plist. and it may solve your issue i think. otherwise your code is perfect.

You can refer this answer for more key and it's description!