ios-上传图片到后台
做第一个项目时,有个版块的个人信息的编辑涉及到头像修改,老大说项目里有通用的代码,让我自己去找。总算找到,搞了许久才弄好,看来理解能力还需要提高啊!!
#pragma mark- 修改头像上传后保存
-(void)uploadMyIco
{
//NSString *fileName = @"myico.jpg";
UIImage *image1 = self.headImageVie.image; NSData *data;
float v = image1.size.width / ;
CGSize newSize = CGSizeMake(image1.size.width / v, image1.size.height / v);
UIGraphicsBeginImageContext(newSize);
[image1 drawInRect:CGRectMake(, , newSize.width, newSize.height)];
UIImage *scaleImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
data = UIImageJPEGRepresentation(scaleImage, 0.8);
UIImage *image = [UIImage imageWithData:data];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil );
NSString *fileNamess =[self createImgFileName];
NSString* filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileNamess];
[data writeToFile:filePath atomically:NO];
NSMutableArray *imageArray = [[NSMutableArray alloc]init];
[imageArray addObject:[NSDictionary dictionaryWithObject:filePath forKey:@"file"]];
self.request = nil;
requestType = ;
self.request = [UPRequest uploadPhotoInfo1:@"member/updatePhoto" image:imageArray keyName:@"file" delegate:self params:nil];
[SKProgressView ShowHudInView:self.view withTag:];
} - (NSString *)createImgFileName
{
static int seedNum = ;
if(seedNum >= )
seedNum = ;
seedNum++; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
// [dateFormatter release]; NSString *file = [NSString stringWithFormat:@"temppics%@%03d.jpg", currentDateStr, seedNum];
return file;
}
部门logo修改是是参照写的〜
#pragma mark- 图像上传保存
- (void)uploadDepartmentLogo//上传部门logo图片
{
NSString *fileName = @"departMentLogo.jpg";
UIImage *image1 = self.headImageView.image;
NSData *data;
if ( UIImagePNGRepresentation(image1) == nil )
{
data = UIImageJPEGRepresentation(image1, );
fileName = @"departMentLogo.png";
} else {
data = UIImagePNGRepresentation(image1);
fileName = @"departMentLogo.jpg";
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:fileName];
[data writeToFile:fullPathToFile atomically:NO]; NSMutableArray *array = [NSMutableArray arrayWithCapacity:];
[array addObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:] forKey:@"type"]];
[array addObject:[NSDictionary dictionaryWithObject:self.deptId forKey:@"deptId"]]; NSMutableArray *imageArray = [[NSMutableArray alloc]init];
[imageArray addObject:[NSDictionary dictionaryWithObject:fullPathToFile forKey:@"file"]];//deptHead self.request = nil;
requestType = ;
self.request = [UPRequest uploadPhotoInfo1:@"dept/uploadPhoto" image:imageArray keyName:@"file" delegate:self params:array];
}
ios-上传图片到后台的更多相关文章
- iOS 直播-实现后台录音并推流
iOS 直播-实现后台录音并推流 从一个月前开始开始接收公司的直播类app.到今天为止测试都已接近尾声,但是产品哥哥加了一个要求,就是在app进入后台后也实时保证录音并且推流. 刚听到这个的时候我也是 ...
- iOS开发小技巧--iOS程序进入后台运行的实现
iOS程序进入后台运行的实现 视频中看到老师用的iOS7,代码中有开启timer,无限请求数据的功能,但是切换到后台,代码就不打印了 自己用的iOS9,进入后台还是可以打印的,再次进入前台也可以正常运 ...
- ios xmpp开发应用后台模式接收聊天信息处理方案
ios xmpp开发应用后台模式接收聊天信息 最近在使用xmppframwork来实现一个聊天应用,碰到了一个问题,应用进入后台以后,就接收不到消息了: 怎么样才能使应用被切到后台时,应用中的网络连接 ...
- iOS程序进入后台后仍运行定时器NSTimer
由于本应用需要在应用进入后台后还要进行定时的检测功能,因此对于我来说怎样让APP在进入后台后 保持运行状态是比较大的需求.然后在iOS系统中是很难实现的,不管是 通过 音频还是 定位系统,我查找了一些 ...
- 实现iOS长时间后台的两种方法:Audiosession和VOIP(转)
分类: Iphone2013-01-24 14:03 986人阅读 评论(0) 收藏 举报 我们知道iOS开启后台任务后可以获得最多600秒的执行时间,而一些需要在后台下载或者与服务器保持连接的App ...
- ios播放声音中断后台音乐的问题
今天遇到一个ios播放声音中断后台音乐的问题,在我的app中如果调用AVAudioSession 播放完声音,后台的qq音乐偶尔不能恢复,而网易云音乐一次都不能恢复播放,研究了一下AVAudioS ...
- 实现iOS长时间后台的两种方法:Audiosession和VOIP
http://www.cocoachina.com/applenews/devnews/2012/1212/5313.html 我们知道iOS开启后台任务后可以获得最多600秒的执行时间,而一些需要在 ...
- 使用WebUploader客户端批量上传图片,后台使用springMVC接收实例
使用WebUploader客户端批量上传图片,后台使用springMVC接收实例 我是搞Java后台的,因为最近主管让用webUploader写客户端,但是在网上找了很多,能够复制就能用的并没有几个, ...
- IOS上传图片方法类
IOS上传图片方法类 iPhone开发中遇到上传图片问题,找到多资料,最终封装了一个类,请大家指点,代码如下 // // RequestPostUploadHelper.h // demodes ...
- android系统和ios系统是如何实现推送的,ios为什么没有后台推送
ios系统为什么没有后台推送? iOS 为了真正地为用户体验负责,不允许应用在后台活动.有了这个限制,但是对于终端设备,应用又是有必要“通知”到达用户的,随时与用户主动沟通起来的(典型的如聊天应用). ...
随机推荐
- Dockerfile文件详解
什么是dockerfile? Dockerfile是一个包含用于组合映像的命令的文本文档.可以使用在命令行中调用任何命令. Docker通过读取Dockerfile中的指令自动生成映像. docker ...
- CSS 简介 4
css css尺寸属性 height 设置元素的高度 line-height 设置行高 max-height 设置元素的最大高度 max-width 设置元素的最大宽度 min-height 设置元素 ...
- (免费电影)苹果手机合并.ts视频
代码教程:https://mp.weixin.qq.com/s/6Oo8TOruePUxotC11zp0ag
- 【读书笔记】Cronjob原理及源码分析
原文链接:https://mp.weixin.qq.com/s?__biz=MzI0NjI4MDg5MQ==&mid=2715291842&idx=1&sn=e605f9b40 ...
- numpy最大值和最大值索引
a= np.array([9, 12, 88, 14, 25])list_a = a.tolist() list_a_max_list = max(list_a) #返回最大值max_index = ...
- OpenStack笔记
*********virsh xml文件解读****************************** https://libvirt.org/format.html https://libvirt ...
- micro-template改造
(function ($) { $.fn.razor = function (data) { var render=$(this).data('razor'); if (!render) { var ...
- 『TensorFlow』分类问题与两种交叉熵
关于categorical cross entropy 和 binary cross entropy的比较,差异一般体现在不同的分类(二分类.多分类等)任务目标,可以参考文章keras中两种交叉熵损失 ...
- html 存放PDF文档
<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="100%" hei ...
- vue配置编译本地打开dist/index.html文件
项目完成后npm run build会生成dist文件,此时直接将dist文件发布到线上即可,若想本地打开dist/index.html可看,一般页面为空,或者报错找不到css和js文件,则需要更改一 ...