Iphone 应用程序在10秒后崩溃或执行;renderInContext“;12次或以上
我使用以下代码将HTML转换为PDFIphone 应用程序在10秒后崩溃或执行;renderInContext“;12次或以上,iphone,ios,objective-c,ios5,Iphone,Ios,Objective C,Ios5,我使用以下代码将HTML转换为PDF UIGraphicsBeginPDFContextToFile(self.filePath, CGRectZero, nil); //creating PDF int i = 0; for (; i < pages; i++) { if (pageHeight * (i+1) > height) { CGRect f = [myWebPage frame];
UIGraphicsBeginPDFContextToFile(self.filePath, CGRectZero, nil); //creating PDF
int i = 0;
for (; i < pages; i++)
{
if (pageHeight * (i+1) > height)
{
CGRect f = [myWebPage frame];
f.size.height -= (((i+1) * pageHeight) - height);
[myWebPage setFrame: f];
}
// Specify the size of the pdf page
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, width, pageHeight), nil);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[[[myWebPage subviews] lastObject] setContentOffset:CGPointMake(0, pageHeight * i) animated:NO];
[myWebPage.layer renderInContext: currentContext];
NSLog(@"I = %d",i);
}
UIGraphicsEndPDFContext();
[[[myWebPage subviews] lastObject] setContentOffset:CGPointMake(0, 0) animated:NO];
[myWebPage setFrame:origframe];
我也尝试过“CGContextRelease(currentContext);”,但它不起作用
我可以知道为什么它会崩溃,以及如何防止应用程序崩溃
控制台输出:
2013-06-06 10:15:26.179 app[8084:907] Width : 980.000000
2013-06-06 10:15:26.180 app[8084:907] NUMBER OF PAGES : 15
2013-06-06 10:15:26.382 app[8084:907] I = 0
2013-06-06 10:15:28.400 app[8084:907] I = 1
2013-06-06 10:15:28.903 app[8084:907] I = 2
2013-06-06 10:15:30.330 app[8084:907] I = 3
2013-06-06 10:15:31.524 app[8084:907] I = 4
2013-06-06 10:15:32.641 app[8084:907] I = 5
2013-06-06 10:15:33.470 app[8084:907] I = 6
2013-06-06 10:15:34.634 app[8084:907] I = 7
2013-06-06 10:15:35.791 app[8084:907] I = 8
2013-06-06 10:15:36.970 app[8084:907] I = 9
2013-06-06 10:15:38.108 app[8084:907] I = 10
2013-06-06 10:15:38.927 app[8084:907] I = 11
和应用程序在iPhone中崩溃(在模拟器中正常工作)
(更新):
在其他情况下,其显示:
2013-06-06 11:17:33.023 app[8202:907] Width : 320.000000
2013-06-06 11:17:33.024 app[8202:907] NUMBER OF PAGES : 2
2013-06-06 11:17:38.200 app[8202:907] I = 0
2013-06-06 11:17:41.390 app[8202:907] I = 1
2013-06-06 11:17:44.028 app[8202:2103] void SendDelegateMessage(NSInvocation *): delegate (webView:didFinishLoadForFrame:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
(lldb)
及
libsystem\u kernel.dylib`mach\u msg\u陷阱:
0x3aa45e1c:mov r12,sp
0x3aa45e20:推送{r4,r5,r6,r8}
0x3aa45e24:LDMR12,{r4,r5,r6}
0x3aa45e28:mvn r12,#30
0x3aa45e2c:svc#128
0x3aa45e30:pop{r4,r5,r6,r8}您的循环阻塞主线程的时间过长。当主线程在10秒钟内没有响应看门狗时,iOS看门狗进程将终止您的应用程序,但0x8badfood除外
你需要把工作分解成几个部分,这样主线程每8秒或9秒就有时间与iOS对话。或者将工作移动到其他线程。AWebView
具有符合WebFrameLoadDelegate
的委托协议frameLoadDelegate
您可以实现的方法之一是
-(void)webView:(webView*)发送方未完成加载框架:(WebFrame*)框架
你的坠机事件正在显现
2013-06-06 11:17:44.028 app[8202:2103]无效
SendDelegateMessage(NSInvocation*):委派
(webView:didFinishLoadForFrame:)在等待10后返回失败
秒。主运行循环模式:KCFRUnlopDefaultMode
这表明默认实现可能存在问题
您可能希望将myWebPage
上的frameLoadDelegate
设置为某个任意对象(可能是拥有myWebPage的对象),并将该方法实现为空
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
//nothing to see here, move along
}
错误是什么?崩溃来自哪行代码?应用程序正在崩溃..它在“[myWebPage.layer RenderContext:currentContext];”处崩溃。是的,我们知道你的应用程序正在崩溃。但你需要提供更多关于坠机的细节。控制台中出现了什么错误?如果你从Xcode运行你的应用程序,堆栈跟踪显示了什么?你应该看到我试着把它分成2个循环。。10次迭代中的每一次。。但它仍在崩溃。。你能根据上面的代码建议或给出一些示例代码吗?你必须在10秒内从函数返回,这样UIApplication才能再次获得控制权。你不能只是打破循环,你必须放弃控制。
libsystem_kernel.dylib`mach_msg_trap:
0x3aa45e1c: mov r12, sp
0x3aa45e20: push {r4, r5, r6, r8}
0x3aa45e24: ldm r12, {r4, r5, r6}
0x3aa45e28: mvn r12, #30
0x3aa45e2c: svc #128
0x3aa45e30: pop {r4, r5, r6, r8} <=== Thread 1: singal SIGSTOP
0x3aa45e34: bx lr
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
//nothing to see here, move along
}