0
我在Google搜索上花了很多時間,但是我沒有得到好的結果。 我將UIWebView轉換爲PDF,具有長contentize(webview中滾動的ContentSize)的webview。renderInContext多次崩潰時的應用程序
我使用RenderInContext for循環,但它使崩潰時,我用webview轉換長 請幫助我解決這個錯誤與20頁。
這是我的代碼:
UIGraphicsBeginPDFContextToFile(documentDirectoryFilename, CGRectMake(0, 0, aWebView.scrollView.contentSize.width, screenHight), nil);
aWebView.scrollView.contentSize.width, screenHight), nil);
for (int i = 0; i < 20; i++) {
@autoreleasepool {
UIGraphicsBeginPDFPage();
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[[[aWebView subviews] lastObject] setContentOffset:CGPointMake(0, screenHight * i) animated:NO];
[aWebView.layer renderInContext:currentContext];
currentContext = nil;
}
}
UIGraphicsEndPDFContext();
aWebView.layer.contents = nil;
我用autoReleasePool並保存結果文件。但它也會導致崩潰。
謝謝您的回答。你的代碼和我的代碼一樣。如果您在20秒內renderInContext in for循環。它會讓你的應用崩潰。我確定我用上面的代碼測試了更多的時間 我知道的是renderInContext不會在循環中釋放內存。這裏最大的問題是如何在使用renderInContext一次之後釋放上下文?我使用ARC並嘗試使用:CGContextRelease(currentContext)。但它不能工作 其他最好的主意?請幫幫我 –