//保存
 
    UIButton *saveBtn = [[UIButton alloc] init];
    //    saveBtn.frame = CGRectMake((screenWidth-270)/4+1, 550/9*screenScale + 272/9*screenScale + 128/9*screenScale + 172/9*screenScale + 55,133, 42);
    saveBtn.frame = CGRectMake((screenWidth-270)/4+1,1766/3,133, 42);
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setBackgroundColor:[UIColor colorWithRed:58/256.0 green:150/256.0 blue:253/256.0 alpha:1.0f]];
    [saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.view addSubview:saveBtn];

-(void)save
{
    NSLog(@"---save");
    //    //如果你的系统大于等于7.0 >
//     if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
//    
//         UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:@"保存二维码到相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
//         alertView.tag = 1;
//         [alertView show];
//    
//    }else{
//    
//        //>=iOS8以上才有alertController这个方法
//        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"保存二维码到相册" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//            UIImageWriteToSavedPhotosAlbum(_codeView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
//        }];
//        
//        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//            
//        }];
//        
//        [alertController addAction:cancelAction];
//        [alertController addAction: okAction];
//        [self presentViewController:alertController animated:YES completion:nil];
//    
//}

UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:@"保存二维码到相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    alertView.tag = 1;
    [alertView show];

}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    
    if (error == nil) {
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",nil];
        alertView.tag = 2;
        [alertView show];
        
    }else{
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请去设置-隐私-照片打开允许访问" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
         alertView.tag = 3;
        [alertView show];
    }
    
}

#pragma mark uialertview deleagate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

if (buttonIndex == 0 && alertView.tag ==1) {
        
        UIImageWriteToSavedPhotosAlbum(_codeView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    }else if(buttonIndex == 0 && alertView.tag==3){
     
    //打开设置-隐私-照片
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    
    }

}

IOS开发之——保存图片到相册的功能实现的更多相关文章

  1. IOS开发-OC学习-常用功能代码片段整理

    IOS开发-OC学习-常用功能代码片段整理 IOS开发中会频繁用到一些代码段,用来实现一些固定的功能.比如在文本框中输入完后要让键盘收回,这个需要用一个简单的让文本框失去第一响应者的身份来完成.或者是 ...

  2. iOS开发之获取系统相册ALAssetLibrary

    注:当你选择看这篇博客时想必你的应用还支持iOS8一下系统,如果你的应用要求最低版本大于iOS8,建议使用PhotoKit框架,效率更高 ALAssetsLibrary包含,ALAssetsLibra ...

  3. iOS开发——高级技术&摇一摇功能的实现

    摇一摇功能的实现 在AppStore中多样化功能越来越多的被使用了,所以今天就开始介绍一些iOS开发的比较实用,但是我们接触的比较少的功能,我们先从摇一摇功能开始 在 UIResponder中存在这么 ...

  4. 分分钟解决iOS开发中App启动广告的功能

    前不久有朋友需要一个启动广告的功能,我说网上有挺多的,他说,看的不是很理想.想让我写一个,于是乎,抽空写了一个,代码通俗易懂,简单的封装了一下,各种事件用block回调的,有俩种样式的广告,一种是全屏 ...

  5. iOS开发 - Swift使用GCD实现计时器功能

    前言 开发中,经常会用到定时执行网络请求.倒计时.计时器等功能,本篇文章介绍在iOS开发中,Swift怎样使用GCD实现这些功能. 执行一次 下面的代码将会在5秒后执行,且只执行一次. let tim ...

  6. iOS开发——UI_swift篇&UITableView实现索引功能

    UITableView实现索引功能     关于UItableView的索引在平时项目中所见不多,最多的就是跟联系人有关的界面,虽然如此,但是作为一个swift开发的程序必须知道的一个技术点,所以今天 ...

  7. iOS开发小技巧--相机相册的正确打开方式

    iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...

  8. iOS开发——高级技术&二维码功能的实现

    二维码功能的实现 ZBarSDK,一个比较优秀的开源项目,使用起来也很简单. ZBarSDK是一个开源的SDK,可从这里下载到源码,该SDK实现了识别和读取各种条形码,包括EAN-13/UPC-A, ...

  9. iOS开发检测是否开启定位、是否允许消息推送等权限

    1.iOS开发检测是否开启定位: 需要导入: #import <CoreLocation/CoreLocation.h> 代码如下: + (void)openLocationService ...

随机推荐

  1. I/O多路复用——select函数与poll函数

    1 区别 同:(1)机制类似,本质上没有多大差别,管理多个描述符也是进行轮询,根据描述符的状态进行处理.(2)包含大量文件描述符的数组被整体复制于用户态和内核的地址空间之间,而不论这些文件描述符是否就 ...

  2. new与malloc的区别

    看起来,它们的不同只是new比malloc用起来更方便而已.仅仅是这样吗?不是吗? 1 来源不同: 1)new/delete是C++中的操作符,而malloc/free是C中的标准库函数,需要库文件支 ...

  3. CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)

    这篇文章主要介绍了CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)的方法,需要的朋友可以参考下 文章写的不错,很详细:IDO转载自网络: 准备篇: 1.配置防火墙,开启 ...

  4. Sqlserver创建连接MySql的链接服务器

    第一步:在MySql服务器上安装与系统对应的 MySql-Connector-ODBC  官方下载地址 安装过程中可能会报 缺失 msvcr100.dll 的错误,这需要你根据系统到网上下载对应的这个 ...

  5. CentOS下搭建SVN服务器

    1.安装SVN SVN数据存储有两种方式,BDB(事务安全表类型)和FSFS(一种不需要数据库的存储系统),为了避免在服务器连接中断时锁住数据,FSFS是一种更安全也更多人使用的方式.SVN的运行方式 ...

  6. ArcGIS API for JavaScript Beta初步试探(一)

    这段时间一直在看https://developers.arcgis.com/javascript/beta/sample-code/index.html, 下面直接看图片: 叠加了二维arcgis s ...

  7. 常用HTML正则

    <?php //HTML a连接正则 $str = ''; $isMatched = preg_match('/<a.*?[^<]>.*?<\/a>/', $str ...

  8. html列表

    有序列表 <ol type="A", start="C"> <!--ordered list--> <li>第一项</ ...

  9. javascript 特效实现(3)—— 鼠标滑过显示二级菜单效果

    1. 关键代码:使用 switch 或 if 判断语句,改变对应的二级菜单显示方式为 block 或 none function selectTabMenu(i){ switch(i){ case 7 ...

  10. nyoj 667 碟战 最小割(最大流)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=677 题意转化:将点0与所有的有间谍的点相连,则题意变为求点0到点n的最小割,直接套最大流 ...