设为首页 加入收藏

TOP

AFNetworking二次封装的那些事(四)
2017-10-13 09:53:59 】 浏览:1100
Tags:AFNetworking 封装 那些
OL * _Nonnull stop) { if ([obj isKindOfClass:[NSString class]] && ([obj hasSuffix:@".png"] || [obj hasSuffix:@".jpg"] || [obj hasSuffix:@".jpeg"])) { [formData appendPartWithFileURL:obj name:key fileName:[NSString stringWithFormat:@"%@.jpg",key] mimeType:@"image/jpeg" error:nil]; } else if ([obj isKindOfClass:[UIImage class]]) { UIImage *image = obj; if (image.size.height > 1080 || image.size.width > 1080) { image = [image imageWithMaxSide:1080]; [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 0.3f) name:key fileName:[NSString stringWithFormat:@"%@.jpeg",key] mimeType:@"image/jpeg"]; } else if (image.size.height > 600 || image.size.width > 600) { [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 0.5f) name:key fileName:[NSString stringWithFormat:@"%@.jpeg",key] mimeType:@"image/jpeg"]; } else { [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 1) name:key fileName:[NSString stringWithFormat:@"%@.jpeg",key] mimeType:@"image/jpeg"]; } } else if ([obj isKindOfClass:[NSArray class]]) { NSArray *array = parameters[key]; for (int i = 0; i < array.count; i++) { id subvalue = array[i]; if ([subvalue isKindOfClass:[UIImage class]]) { UIImage *image = subvalue; if (image.size.height > 1080 || image.size.width > 1080) { image = [image imageWithMaxSide:1080]; [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 0.3f) name:key fileName:[NSString stringWithFormat:@"%@.jpeg",key] mimeType:@"image/jpeg"]; } else if (image.size.height > 600 || image.size.width > 600) { [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 0.5f) name:key fileName:[NSString stringWithFormat:@"%@.jpeg",key] mimeType:@"image/jpeg"]; } else { [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 1) name:key fileName:[NSString stringWithFormat:@"%@.jpeg",key] mimeType:@"image/jpeg"]; } } else if ([subvalue isKindOfClass:[NSString class]] && ([subvalue hasSuffix:@".png"] || [subvalue hasSuffix:@".jpg"] || [subvalue hasSuffix:@".jpeg"])) { [formData appendPartWithFileURL:obj name:key fileName:[NSString stringWithFormat:@"%@.jpg",key] mimeType:@"image/jpeg" error:nil]; } } } else if ([obj isKindOfClass:[NSData class]]) { [formData appendPartWithFileData:obj name:key fileName:[NSString stringWithFormat:@"%@.mp3",key] mimeType:@"audio/mp3"]; } }]; } }

对于AF的二次封装很多,不过追本溯源就是NSURLSession,就是http协议.

结尾

这次独立带项目,真的学到了很多,明白了自己的很多不足.更让我明白理论真的很重要.大学的课程真的有他的必要性.

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇安装Cocoapods时候ERROR: While e.. 下一篇AFNetworking二次封装的那些事

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目