IOS开发之—— 上传头像的使用
static NSString *const uploadSuccess = @"更改头像成功";
@interface DMAccountInformationViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate,AVAudioPlayerDelegate>
@property (nonatomic, strong) UIImageView *pictureImageView; //头像
@property (nonatomic, strong) UIImage *changeImage;
#pragma mark - ---------------- 事件 ------------------
#pragma mark - 选择照片
- (void)choosePhotoAction
{
UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从相册中选取", nil];
[actionSheet showInView:self.view];
}
#pragma mark -actionsheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if (buttonIndex==0) {
NSString * mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if (authorizationStatus == AVAuthorizationStatusRestricted|| authorizationStatus == AVAuthorizationStatusDenied) {
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"摄像头访问受限" message:nil preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertC animated:YES completion:nil];
UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[alertC addAction:action];
}else
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"摄像头访问受限" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alertView show];
}
}else{
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
}
else
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"该设备相机不能使用" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
[alert show];
}
}else if (buttonIndex==1)
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
#pragma mark - ---------------- 请求 ------------------
#pragma mark - 上传图片请求
- (void)uploadImgRequestWithPatameters:(NSDictionary *)parameters
{
[DMHttpRequest postUploadFile:DMUploadIconUrl parameters:parameters success:^(id responseObj) {
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingAllowFragments error:nil];
DMRequestCode code = [DMTools responseCode:dictionary];
NSLog(@"!!%@!!",dictionary);
switch (code) {
case DMRequestSuccess:
{
NSLog(@"!!%@!!",dictionary);
[DMTools loadSuccessHUD:self.hud text:uploadSuccess delay:DMHUDDelayTimeInterval];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSDictionary *imageDic = [dictionary objectForKey:@"data"];
NSString *imageStr = [imageDic objectForKey:@"url"];
dispatch_async(dispatch_get_main_queue(), ^{
[DMUserLogInfoModel shareInstance].userData.avatar = imageStr;
[DMUserDataManager saveUserData:[DMUserLogInfoModel shareInstance].userData.keyValues];
_pictureImageView.image = _changeImage;
});
});
dispatch_get_main_queue(), ^{
break;
}
default:
[DMTools loadFailedHUD:self.hud text:[DMTools responseMessage:dictionary] delay:DMHUDDelayTimeInterval];
break;
}
} failure:^(NSError *error) {
[DMTools loadFailedHUD:self.hud text:DMRequestFailureNote delay:DMHUDDelayTimeInterval];
}];
}
IOS开发之—— 上传头像的使用的更多相关文章
- IOS开发-图片上传
目前IOS端开发,图片上传到服务器分为两种,一种是直接上到服务器,一种是借助第三方储存(减少服务器压力). 一.直接上传到服务器 /** * 代码演示 */ //*******UIImagePNGRe ...
- iOS开发 multipart 上传多张图片
- (void)uploade:(NSDictionary *)dic pic:(NSArray *)picArray { NSString *hyphens = @"--" ...
- iOS开发App上传的三大步骤
上传流程 1.itunse connect中->“我的App”中新建创建应用,填写相关的信息 a.项目名称(多创建几个),避免重名 b.想好应用的类型 c.应用截图(5.5,4.7,4,3.5寸 ...
- iOS开发--CornerStone上传静态库(.a文件)
首先打开软件左上角 CornerStone-Preferences-SubVersion 第一个地方把对号去掉,第二个地方把.a那个删除,然后save. 然后把你的.a文件放到本地的相应文件夹下, 但 ...
- python 全栈开发,Day86(上传文件,上传头像,CBV,python读写Excel,虚拟环境virtualenv)
一.上传文件 上传一个图片 使用input type="file",来上传一个文件.注意:form表单必须添加属性enctype="multipart/form-data ...
- 【iOS 使用github上传代码】详解
[iOS 使用github上传代码]详解 一.github创建新工程 二.直接添加文件 三.通过https 和 SSH 操作两种方式上传工程 3.1https 和 SSH 的区别: 3.1.1.前者可 ...
- Android基础之——startActivityForResult启动界面并返回数据,上传头像
在android应用的开发过程中,常常会出现启动一个界面后填写部分内容后带着数据返回启动前的界面,最典型的应用就是登录过程.在非常多应用程序的模块中,都有"我的"这个模块,在未登录 ...
- flask 上传头像
上传头像,自己感觉了好久,就是上传文件呗其实,存在一个路径,数据库存储这个路径,然后展示给前端,啥都不说,看怎么实现的. 数据库设置如下 user_image=db.Column(db.String( ...
- .net mvc 上传头像
我用的是mvc5 开发环境vs2017 [仅供参考] [视图代码] <div > <img src="@path" alt="@att.Count&q ...
随机推荐
- su su -
http://www.ha97.com/4001.html su命令和su -命令最大的本质区别就是:前者只是切换了root身份,但Shell环境仍然是普通用户的Shell:而后者连用户和Shell环 ...
- 编写一个Java项目,定义包,在包下定义包含main方法的类,在main方法中声明8种基本数据类型的变量并赋值,练习数据类型转换。
- Eclipse 启动Tomcat 超时报错的解决方案
在用eclipse开发项目 用tomcat发布项目的时候 会提示超时, Server Tomcat v7.0 Server at localhost was unable to start wit ...
- nginx根据IP限制访问
nginx有两个模块可以控制访问 HttpLimitZoneModule 限制同时并发访问的数量 HttpLimitReqModule 限制访问数据,每秒内最多几个请求 http{ ## ...
- Linux 安装 redis
环境:centos7 参考:http://blog.csdn.net/lk10207160511/article/details/50364088 步骤如下: 安装redis: 打开终端 输入 s ...
- Swift 语法笔记01
Swift 好多新奇的地方啊...妈的 var display: int { get() set() } Tuple: let x: (d:Double, e:String, f:Int) = (3. ...
- 3D俄罗斯方块设计
发布在博客:http://blog.sina.com.cn/s/blog_d38e811c0101cpis.html
- CSS select样式优化 含jquery代码
CSS 下拉选择菜单基本的CSS样式不怎么好看,通过一些简单的样式优化,可以得到如下图这样的: html结构如下: <div class="sel_wrap"> < ...
- URAL 1416 Confidential --最小生成树与次小生成树
题意:求一幅无向图的最小生成树与最小生成树,不存在输出-1 解法:用Kruskal求最小生成树,标记用过的边.求次小生成树时,依次枚举用过的边,将其去除后再求最小生成树,得出所有情况下的最小的生成树就 ...
- 最长回文子串Manacher算法模板
Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 首先,在字符串s中,用rad[i]表示第i个字符 ...