在UIWebView中打开PDF文件时,iOS 8应用程序崩溃

时间:2014-09-29 17:35:19

标签: javascript objective-c pdf uiwebview ios8

我有一个运行到iOS上的UIWebView的Javascript应用程序。此应用程序将命令发送到本机应用程序(Objective-C)以控制其行为,如更改状态栏的颜色,或打开另一个UIWebView以加载外部Web页面或文件。

自iOS 8发布以来,我收到了大量的崩溃报告,这些报告都是由同一错误生成的。我能够在iOS 8上用iPhone 5S重现崩溃。

当我打开和关闭几个带有PDF文件链接的外部UIWebView时,应用程序会在4-5次后崩溃。这是崩溃报告中的崩溃线程:

Exception Type:  EXC_CRASH (SIGSEGV)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib        0x370d8ba8 __psynch_mutexwait + 24
1   libsystem_pthread.dylib       0x371541fa _pthread_mutex_lock + 274
2   WebCore                       0x346407cc _WebTryThreadLock(bool) + 40
3   WebCore                        0x34640fe8 WebThreadLock + 76
4   UIKit                         0x2d4e1be0 -[UIWebBrowserView _webTouchEventsRecognized:] + 520
5   UIKit                         0x2d36b556 -[UIWebTouchEventsGestureRecognizer _processTouches:withEvent:type:] + 294
6   UIKit                         0x2d36b6c6 -[UIWebTouchEventsGestureRecognizer touchesBegan:withEvent:] + 146
7   UIKit                          0x2d013538 -[UIWindow _sendGesturesForEvent:] + 408
8   UIKit                         0x2d012f88 -[UIWindow sendEvent:] + 520
9   UIKit                         0x2cfe9a04 -[UIApplication sendEvent:] + 192
10  UIKit                         0x2d25bade _UIApplicationHandleEventFromQueueEvent + 13842
11  UIKit                         0x2cfe849c _UIApplicationHandleEventQueue + 1300
12  CoreFoundation                0x299b257c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
13  CoreFoundation                0x299b198a __CFRunLoopDoSources0 + 214
14  CoreFoundation                0x299afff0 __CFRunLoopRun + 768
15  CoreFoundation                0x298fe60c CFRunLoopRunSpecific + 472
16  CoreFoundation                0x298fe41e CFRunLoopRunInMode + 102
17  GraphicsServices              0x30e580a4 GSEventRunModal + 132
18  UIKit                         0x2d048480 UIApplicationMain + 1436
19  MyApp                          0x000c5472 main (main.m:16)
20  libdyld.dylib                  0x37012aac start + 0

这是代码中文件下载完成后调用新Web视图的部分。最后,本机应用程序调用Javascript方法告诉我的JS应用程序该文件已被下载。

即使我打破了这段代码,我也不知道它崩溃的地方。

NSLog(@"Download completed");
docPath = [docPath stringByAppendingPathComponent:filename];
if (![docPath isEqualToString:docPath]) {
      [[NSFileManager defaultManager] removeItemAtPath:docPath error:&error];
}
bool saved =[[NSFileManager defaultManager] createFileAtPath:docPath contents:fileData attributes:nil];
if(saved){
      WebViewController *wController = [[WebViewController alloc] init];
      wController.isExternalWebView=true;
      wController.showToolbar=FALSE;
      wController.showNavigationBar=TRUE;
      wController.showActionInNavigationBar=TRUE;
      wController.actions= @[@"Print",@"OpenIn"];
      wController.initialURLRequest=[NSURLRequest requestWithURL:[NSURL fileURLWithPath:docPath]];
      wController.actionSheetTitle=[inArguments objectForKey:@"TextTitlePopup"];
      wController.title=[inArguments objectForKey:@"TextTitle"];
      [weakSelf.navigationItem setBackBarButtonItem: [[UIBarButtonItem alloc]
                                                                       initWithTitle: [inArguments objectForKey:@"TextBackBtn"]
                                                                       style: UIBarButtonItemStyleBordered
                                                                       target: nil action: nil]];

      [weakSelf.navigationController pushViewController:wController animated:YES];
}else{
      NSLog(@"COULD NOT SAVE FILE");
}

NSLog(@"START!");
[self.downloadOperation  start];

NSString *jsString = [NSString stringWithFormat:@"App.DocumentCallBack();"];
[mWebView stringByEvaluatingJavaScriptFromString:jsString];

自iOS 8发布以来,我的Javascript和Objective-C的代码没有改变。在iOS 7中,这种崩溃在一个月内只发生了几次。现在,它每天发生超过100次。

有谁知道什么会导致这个问题?谢谢你的帮助。

0 个答案:

没有答案