下面是代码,当我使用iOS6.1下的设备时,[self presentModalViewController:imagePicker animated:YES];会崩溃。它在iOS 7中运行得很好。
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init] ;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imagePicker animated:YES];
}获取控制台中的错误: ImageIO: PNG无效PNG文件: iDOT没有指向有效的IDAT块
如有任何建议,将不胜感激。
发布于 2014-04-18 06:30:17
好的,我已经修复了错误,我想分享它的细节过程。
当它崩溃时,它会显示ImageIO: PNG无效的PNG文件: iDOT没有指向有效的IDAT块libc++abi.dylib:处理程序在控制台中抛出异常,我不知道"ImageIO balabala.“但是当我注意到"libc++abi.dylib: handler抛出异常“时,我想我可能会捕捉到异常。因此,我在代码中添加了“try @catch”,代码如下。
@try {
[self presentModalViewController:imagePicker animated:YES] ;
}
@catch (NSException *exception) {
NSLog(@"exception:%@", exception) ;
}
@finally {
}然后我再次运行它,得到exception:preferredInterfaceOrientationForPresentation必须返回一个受支持的接口方向!。
这个问题似乎有点明显,谷歌之后,我找到了一个解决方案,就是覆盖一些与方向相关的方法,以便在UIImagePickerController中提供一个首选的接口方向。
因此,我对UIImagePickerController进行了子类化,并实现了如下一些方法:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}然后再跑一次,没有碰撞,干杯!
https://stackoverflow.com/questions/23146555
复制相似问题