Reputation: 6952
Code is below and crash at [self presentModalViewController:imagePicker animated:YES];
when I use device under iOS6.1. It work fine in iOS 7.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init] ;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imagePicker animated:YES];
}
Get the error in console: ImageIO: PNG invalid PNG file: iDOT doesn't point to valid IDAT chunk
Any suggestion is appreciated.
Upvotes: 0
Views: 679
Reputation: 6952
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 !!!
Upvotes: 1
Reputation: 742
Replace this line:
[self presentModalViewController:imagePicker animated:YES];
With
[self presentViewController:picker animated:YES completion:nil];
Upvotes: 0