{
//self.passURL 是后台返回的可以加載顯示到webView中的PDF鏈接
if ([self.passURL isEqualToString:@""] || self.passURL == nil || [self.passURL isEqual:nil] || !self.passURL) {
[self InvalidAlertView];
return;
}
NSURL *url = [[NSURL alloc] initWithString:self.passURL];
CFURLRef ref = (__bridge CFURLRef)url;
pdf = CGPDFDocumentCreateWithURL(ref);
CFRelease(ref);
CGImageRef imageRef = PDFPageToCGImage(1,pdf);
UIImage *amg = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
//保存圖片到相冊
UIImageWriteToSavedPhotosAlbum(amg, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
if (error == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"圖片已保存到相冊" delegate:self cancelButtonTitle:nil otherButtonTitles:@"好的", nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失敗" delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定", nil];
[alert show];
}
}
問題:在dealloc中 寫CGPDFDocumentRelease(pdf)這個方法,如果保存完照片后,快速點擊返回按鈕會崩潰,如果等2秒后點擊返回不會崩,所以在項目中先屏蔽掉了。
如果有哪位解決了不崩潰,請留個言,謝過了
- (void)dealloc {
// CGPDFDocumentRelease(pdf);
if ([self.mainWebView isLoading]){
[self.mainWebView stopLoading];
}
}
