//保存
 
    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 保存图片至相册

    IOS 保存图片至相册   应用中有时我们会有保存图片的需求,如利用UIImagePickerController用IOS设备内置的相机拍照,或是有时我们在应用程序中利用UIKit的 UIGraphi ...

  2. iOS保存图片到相册崩溃

    项目迭代开发的过程中,有用户反映保存图片到相册崩溃,最终自己测试出,在iOS11以下的手机正常保存,而iOS11之后的手机则会出现反映的问题.打印错误信息如下: This app has crashe ...

  3. IOS UIImagePickerController 保存图片到 相册

    // 异步下载图片 dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0); disp ...

  4. iOS开发——实用篇Swift篇&保存图片到相册

    保存图片到相册 最近在深入的学习关于swift相关技术,虽然海做不出什么好的东西,但是感觉收获不少,相信总有一样能用到,所以就总结了一下,希望大家喜欢! 1.OC中的写法 在OC中,我们需要保存图片到 ...

  5. iOS摄像头和相册-UIImagePickerController常用操作

    在一些应用中,我们需要用到iOS设备的摄像头进行拍照,视频.并且从相册中选取我们需要的图片或者视频. 关于iOS摄像头和相册的应用,可以使用UIImagePickerController类来完成控制. ...

  6. iOS摄像头和相册-UIImagePickerController-浅析

    转载自:http://blog.sina.com.cn/s/blog_7b9d64af0101cfd9.html 在一些应用中,我们需要用到iOS设备的摄像头进行拍照,视频.并且从相册中选取我们需要的 ...

  7. ios中从相册:相机中获取图片信息

    ios中从相册/相机中获取图片信息 从相册中获取图片的信息 UIImagePickerController *imgPickView = [[UIImagePickerController alloc ...

  8. iOS摄像头和相册-UIImagePickerController-浅析(转)

    iOS摄像头和相册-UIImagePickerController-浅析(转) 转自: http://blog.sina.com.cn/s/blog_7b9d64af0101cfd9.html 在一些 ...

  9. ios中摄像头/相册获取图片压缩图片上传服务器方法总结

    本文章介绍了关于ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结,有需要了解的同学可以参考一下下.     这几天在搞iphone上面一个应用的开发,里面有需要摄像头/相册编程和图片上传的问 ...

  10. iOS摄像头和相册(转)

    iOS摄像头和相册iOS 获取图片有三种方法1. 直接调用摄像头拍照 2. 从相册中选择 3. 从图库中选择 UIImagePickerController 是系统提供的用来获取图片和视频的接口: 用 ...

随机推荐

  1. js 正则表达式将 p标签替换 span标签

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. Maven 设置阿里镜像

    Maven 默认的中央仓库速度慢,可以考虑换成阿里的镜像.修改方式主要有两种. 1.针对所有项目修改中央仓库Maven 提供了全局配置文件 settings.xml 针对所有项目有效,位置是在安装目录 ...

  3. 27-SQLServer系统扩展存储过程

    一.注意点 1.在SQLServer中,有些系统扩展存储过程,是有风险,需要取消public角色的执行权限. 2.从SQLServer2005开始就不能通过sp_dropextendedproc 删除 ...

  4. easyUI-filebox图片上传和预览

    转载自:https://blog.csdn.net/nvxiaq/article/details/77740516 备注: 1.如需上传多个图片可定义多个change_photo函数 在onChang ...

  5. 使用selenium实现站长素材图片采集

    from selenium import webdriver import requests,os from lxml import etree from selenium.webdriver.chr ...

  6. python3爬虫系列19之反爬随机 User-Agent 和 ip代理池的使用

    站长资讯平台:python3爬虫系列19之随机User-Agent 和ip代理池的使用我们前面几篇讲了爬虫增速多进程,进程池的用法之类的,爬虫速度加快呢,也会带来一些坏事. 1. 前言比如随着我们爬虫 ...

  7. Fibonacci数性质

    Fibonacci数性质 0.\(F_{n-1}+F_{n-2}=F_{n} ,特殊的 F_{0}=1,F_{1}=1\) 上述式子为定义式 1.\(F_{0}+F_{1}+...+F_{n}=F_{ ...

  8. Codeforces Round #595 (Div. 3) A,B,C,D

    A题:n个学生,分成任意组,要求每组中任意两名学生的技能值相差不等于1,问最小分组. #include<bits/stdc++.h> using namespace std; #defin ...

  9. Flutter 初始化数据完成后再加载页面

    一.初始化数据完成后再加载数据 1.为了达成这个目标尝试了多种方法总是失败 在Init 和didChangeDependencies 初始化数据过也不行 @override void didChang ...

  10. MySQL优化:如何避免回表查询?什么是索引覆盖? (转)

    数据库表结构: create table user ( id int primary key, name varchar(20), sex varchar(5), index(name) )engin ...