0

次のコードを使用して 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];
            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];

しかし、10 秒後または i >= 12 の場合、ループがクラッシュします。

でクラッシュしました:

 [myWebPage.layer renderInContext: currentContext];

「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_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

私を助けてください..

4

2 に答える 2

1

ループがメインスレッドを長時間ブロックしています。iOS ウォッチドッグ プロセスは、メイン スレッドが 10 秒間ウォッチドッグに応答しない場合、例外 0x8badfood でアプリを強制終了します。

メインスレッドが 8 秒または 9 秒ごとに iOS と対話する時間を確保できるように、作業を細かく分割する必要があります。または、作業を他のスレッドに移動します。

于 2013-06-06T08:45:40.640 に答える