iOS PDF文件连接转化为img图片保存到相册
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | { <br> //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 ); }<br><br>- ( 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];
}
}
标签:
iOS PDF文件连接转化为img
, 图片保存到相册
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 从零开始开发一个 MCP Server!
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
2016-11-17 iOS UITableViewCell的分割线向左延长15(cell长度为全宽)