Ok, I have fixed the bug, I want to share it out with detail process.
When it crashes, it shows ImageIO: PNG invalid PNG file: iDOT doesn't point to valid IDAT chunk libc++abi.dylib: handler threw exception in the console, I have no idea about "ImageIO balabala..." but I think I may catch the exception when I noticed "libc++abi.dylib: handler threw exception". So I add @try @catch in my code, code is below.
@try {
[self presentModalViewController:imagePicker animated:YES] ;
}
@catch (NSException *exception) {
NSLog(@"exception:%@", exception) ;
}
@finally {
}
Then I run it again, I got exception:preferredInterfaceOrientationForPresentation must return a supported interface orientation!.
The problem seems to be a little obvious, after google it, I find a solution which is to override some orientation related methods to provide a preferred interface orientation in UIImagePickerController.
So I subclass the UIImagePickerController
and implement some methods like this below:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Then run again, no crash , cheers !!!