Question

I'm using xcode 5.1 and tested the code both on ios7.1 and 7.0.2. The app crashes with UIImagePickerController in two scenarios on the device:

1) when allowsEditing is set to YES, after I crop a picture and press "Choose", as soon as it goes back to my own view, the app crashes

2) inside UIImagePickerController, when I go back from the photo list to the album list and I was at the bottom of the photo list, it crashes (no matter allowsEditing is YES or not). Note it does not crash if I scrolled the photo list up.

Here is my code:

- (IBAction)photoPickPressed:(id)sender {

    if ([self isPhotoLibraryAvailable]) {

        self.imagePicker = [[UIImagePickerController alloc] init];
        self.imagePicker.delegate = self;
        self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        self.imagePicker.allowsEditing = YES;
        NSString *requiredMediaType = (__bridge NSString*)kUTTypeImage;
        self.imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:requiredMediaType, nil];
        [self presentViewController:self.imagePicker animated:YES completion:nil];
    }
}

#pragma mark - image picker delegates
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [picker dismissViewControllerAnimated:YES completion:^(){
        NSLog(@"finished image picking");
    });
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

The crash message is

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSProxy doesNotRecognizeSelector:scrollViewDidScroll:] called!'

Note: it does NOT crash if I use camera even if I set allowsEditing to YES. Also it ONLY crashes on the real devices, not on the simulator.

Just to clarify (maybe unrelated), originally I declared the imagePicker as

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

, and it crashed. So I googled a lot, and a post says the controller might be recycled, and suggested to declare it in the class definition. So now I declared it in my class declartion:

@property (strong, nonatomic) UIImagePickerController *imagePicker;

Thanks in advance.

Update: I tried to even put the invoke of imagePickerController to the root view of my app, and it still crashes with the same message. I shouldn't have any scrollable view loaded yet.

Was it helpful?

Solution

After hours of investigation and tryout, I am confirmed that it is caused by a third-party framework integrated to the app: even that empty app crashes with UIImagePickerController if I link that framework there.

Thank you for the help!

OTHER TIPS

My recommendation would be to remove the imagePickerController: didFinishPickingMediaWithInfo: method. It is completely optional, and will dismiss the image picker by default.

As well as this, I would recommend:

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

    [self dismissViewControllerAnimated:YES completion:nil];
}

According to the documentation, this method should be called on the presenting view controller:

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top