zoukankan      html  css  js  c++  java
  • iOS PDF文件连接转化为img图片保存到相册

    {
    
    //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];

        }

    }

  • 相关阅读:
    js 删除数组的某一项或者几项的方法
    JavaScript 面向对象的程序设计(一)之理解对象属性
    iview 之 穿梭框 transfer
    iview2.0 bug之+8 区的 DatePicker
    js Object.keys 用法
    js map 、filter 、forEach 、every、some 的用法
    iview tree 之如何获取已勾选的节点
    js 中常见的深拷贝的方法
    ES6新特性
    Amazon2014在线笔试 第三题
  • 原文地址:https://www.cnblogs.com/ios988/p/7852344.html
Copyright © 2011-2022 走看看