UIWebview仅在ios7上加载某些pdf文档时崩溃
我有iPhone应用程序,它使用UIWebview仅在ios7上加载某些pdf文档时崩溃,ios,pdf,uiwebview,ios7,Ios,Pdf,Uiwebview,Ios7,我有iPhone应用程序,它使用UIWebview显示文档。 当我试图打开某些pdf文件时,应用程序崩溃,出现以下异常: 0 CoreFoundation 0x036925e4 __exceptionPreprocess + 180, 1 libobjc.A.dylib 0x02c2d8b6 objc_exception_throw + 44, 2 CoreFoundation
UIWebview
显示文档。
当我试图打开某些pdf文件时,应用程序崩溃,出现以下异常:
0 CoreFoundation 0x036925e4 __exceptionPreprocess + 180,
1 libobjc.A.dylib 0x02c2d8b6 objc_exception_throw + 44,
2 CoreFoundation 0x036923bb +[NSException raise:format:] + 139,
3 QuartzCore 0x0126bcaa _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 190,
4 QuartzCore 0x0126be69 -[CALayer setPosition:] + 68,
5 QuartzCore 0x0126c56f -[CALayer setFrame:] + 799,
6 UIKit 0x017e572c -[UIView(Geometry) setFrame:] + 302,
7 UIKit 0x01d14bcb -[UIWebPDFViewHandler didDetermineDocumentBounds:] + 161,
8 UIKit 0x01d0f2b4 -[UIWebPDFView didCompleteLayout] + 628,
9 WebKit 0x069cbac1 -[WebPDFViewPlaceholder _notifyDidCompleteLayout] + 161,
10 libobjc.A.dylib 0x02c3f81f -[NSObject performSelector:withObject:] + 70,
11 Foundation 0x026759d8 __NSThreadPerformPerform + 285,
12 CoreFoundation 0x0361b83f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15,
13 CoreFoundation 0x0361b295 __CFRunLoopDoSources0 + 437,
14 CoreFoundation 0x0363829e __CFRunLoopRun + 910,
15 CoreFoundation 0x03637ac3 CFRunLoopRunSpecific + 467,
16 CoreFoundation 0x036378db CFRunLoopRunInMode + 123,
17 GraphicsServices 0x035bd9e2 GSEventRunModal + 192,
18 GraphicsServices 0x035bd809 GSEventRun + 104,
19 UIKit 0x0178ed3b UIApplicationMain + 1225,
20 Navigator 0x0000317d main + 141,
21 libdyld.dylib 0x041a570d start + 1
显然,此特定pdf文档已损坏,但只有在iOS7上,UIWebview
才会崩溃。在iOS6设备和模拟器上,文件不会显示,但应用程序仍然存在
我希望有人能解释这种差异的来源,更重要的是——如何避免这种情况导致我的应用程序崩溃
编辑:您可以尝试并使用我创建的示例项目来显示问题。
项目在这里:
您可以看到应用程序在运行于ios7模拟器时如何在损坏的文件上崩溃,以及如何在ios6模拟器上生存下来添加此委托方法以避免在出现加载错误时崩溃
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"Error %@", [error description]);
}
至于UIWebView为什么在两个iOS版本之间改变了行为,目前还没有具体的答案。在重大更新期间,许多API都会发生变化
在您的情况下,在.h文件中设置强属性(现在是弱属性),并遵守UIWebView协议:
@interface FlipsideViewController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (nonatomic,strong) NSString * fileName;
- (IBAction)done:(id)sender;
谢谢你的回答@Nikos,但在调用此方法之前应用程序崩溃再次查看此感谢,但我之前看到了此线程,问题不是我的问题编辑了我的答案。尝试后,它成功了,它记录了错误:testWebViewProject[10572]:CGAffineTransformInvert:singular matrix。请注意,现在UIWebview加载不正确,可能在处理文档之前失败。我看到好的文件在这里也失败了。
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (self.fileName==nil) {
self.fileName=@"samplePDF";
}
self.webView = [[UIWebView alloc] init];
NSString *path = [[NSBundle mainBundle] pathForResource:self.fileName ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.webView setDelegate:self];
[self.webView loadRequest:request];
}