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 ...
随机推荐
- SQL获取时间段内的所有月份
select convert(varchar(7),dateadd(month,number,'2010-01-01'),120) AS MONTHfrom master..spt_valueswhe ...
- oracle定时任务
一.简介 当我们需要oracle数据库定时自动执行一些脚本,或进行数据库备份.数据库的性能优化,包括重建索引等工作是需要使用到定时任务. 定时任务可以使用以下两种完成. 1.操作系统级的定时任务,wi ...
- ExtJS提交到服务器端的方式以及简单的登录实现
ExtJS平台已经搭建好了,那么接下来要做网站的登录页面,当然还是在jsp页面里加载extjs的,首先我们先了解一下关于extjs是如何提交到服务器端的: 1.EXT的form表单ajax提交(默认提 ...
- puppet安装
server xuesong1 10.152.14.85 client xuesong 10.152.14.106 系统centos5.8 两台配置都配置 /etc/ho ...
- Hive UDF 实验1
项目中使用的hive版本低于0.11,无法使用hive在0.11中新加的开窗分析函数. 在项目中需要使用到row_number()函数的地方,有人写了udf来实现这个功能. new java proj ...
- 如何做好presentation
1.全心投入 要么不做,要做就做好 承诺自己会花时间好好准备自己的演讲,投入专注的精力. 人们可以通过练习使自己成为很好的演讲者. 2分析你的观众 他们想听什么? 3.组织你的想法 让语言简单 让观众 ...
- JavaScript“尽快失败”的原则
我第一次听说编码原则中有"尽快失败"这一条时,觉得很奇怪,为什么代码要失败?应该成功才对呀.但事实上,当代码在遇到错误的时候应该尽快的终止.为了检测各种状态,我们需要频繁的创建if ...
- 深入理解UIApplication和ios程序启动过程
在深入理解UIApplication前我们先了解ios程序的启动过程: UIApplication类在ios里面为app的管理和协调提供一个集中的点,每一个app有一个UIApplication的实例 ...
- Google三驾马车
Google旧三驾马车: GFS,mapreduce,Bigtable http://blog.sina.com.cn/s/blog_4ed630e801000bi3.html Google新三驾马车 ...
- [转]Source Insight使用小技巧小结
Source Insight是一款强大的代码查看工具,本身支持扩展性很好.下面我们就介绍2个扩展用例. 1.快速打开当前文件所在的目录,这个功能类似于eclipse的easyshell插件,就是能快速 ...