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 ...
随机推荐
- Git+GitHub 使用小结
1.Git安装完成后需要做的配置 $ git config --global user.name "Your Name" $ git confi ...
- jquery错误: Cannot read property ‘msie’ of undefined
背景 Web application, 引用了jquery 1.10.2和fancybox 1.3.4 现象 访问页面遭遇Cannot read property ‘msie’ of undefine ...
- 怎么通过 Microsof Office Project 2010 来写功能开发计划
新建一个Microsof Office Project 2010 功能, 直接填写,可以通过快捷键来改变目录分级情况.(shift+alt+ —> 或者 <—) 也可以通过导航栏上面的摘要 ...
- 百度地图Api进阶教程-点击生成和拖动标注4.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Andorid 内存溢出与内存泄露,几种常见导致内存泄露的写法
内存泄露,大部分是因为程序的逻辑不严谨,但是又可以跑通顺,然后导致的,内存溢出不会报错,如果不看日志信息是并不知道有泄露的.但是如果一直泄露,然后最终导致的内存溢出,仍然会使程序挂掉.内存溢出大部分是 ...
- centos6.7 安装Docker
一.查看系统版本 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.7 (Final) 二.安装EPEL 1.进入cento ...
- git 换行符LF与CRLF转换问题
git 换行符LF与CRLF转换问题 一.背景 在各操作系统下,文本文件所使用的换行符是不一样的.UNIX/Linux 使用的是 0x0A(LF),早期的 Mac OS 使用的是0x0D(CR),后来 ...
- pig 介绍与pig版 hello world
前两天使用pig做ETL,粗浅的看了一下,没有系统地学习,感觉pig还是值得学习的,故又重新看programming pig. 以下是看的第一章的笔记: What is pig? Pig provid ...
- Android逆向工程初步(一) 15.4.24
最近看了看Android的逆向工程,破解的书,像是<Android Hack‘s Book>之类的,感觉挺有意思的,看了看一些smali的语法,试着自己写了个demo玩玩: 1.工具: 最 ...
- HDU 4941 Magical Forest --STL Map应用
题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...