你的位置:首页 > 软件开发 > 操作系统 > IOS 网络浅析-(十一 三方 AFNetworking3.0简介)

IOS 网络浅析-(十一 三方 AFNetworking3.0简介)

发布时间:2016-03-22 21:00:10
AFNetworking3.0是目前最新的版本,本来打算介绍一下2.6,但是想想2.6名不久矣,就决定不介绍了,有兴趣的小伙伴可以上网查一查。下面我就开始进入正题了。 目前使用人数最多的第三方网络库,没有之一。从开始的NSURLConnection到现在的NSURLSessi ...

AFNetworking3.0是目前最新的版本,本来打算介绍一下2.6,但是想想2.6名不久矣,就决定不介绍了,有兴趣的小伙伴可以上网查一查。下面我就开始进入正题了。

 目前使用人数最多的第三方网络库,没有之一。从开始的NSURLConnection到现在的NSURLSession,它都一直保持着与苹果的步调一致,而由它也衍生出大量的相关第三方网络功能库,不仅仅因为他的可靠,好用,一直保持着维护更新,也是为什么它这么受到广大程序员的青睐。

上传data

//// ViewController.m// CX- AFNetworking3.0简介//// Created by ma c on 16/3/22.// Copyright © 2016年 xubaoaichiyu. All rights reserved.//#import "ViewController.h"#import "AFNetworking.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {  [super viewDidLoad];    [self upLoadData];  }//上传data-(void)upLoadData{    UIImage * image = [UIImage imageNamed:@"renminbi.jpg"];    NSData * data = UIImageJPEGRepresentation(image, 1);    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];  /*   POST 上传地址   parameters 文本参数   constructingBodyWithBlock 上传文件的block,有可能多次调用   progress 上传进度   success 上传成功   failure 上传失败   */  [manager POST:@"http://localhost/post/upload.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {        /*         formData 上传的数据         FileData 上传文件的data         name 上传文件的key         fileName 服务器上的名字         mimeType 上传资源的类型         */    [formData appendPartWithFileData:data name:@"userfile00" fileName:@"xubaoaichiyu" mimeType:@"image/jpg"];      } progress:^(NSProgress * _Nonnull uploadProgress) {        NSLog(@"%@",uploadProgress);          } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {        NSLog(@"成功->%@",responseObject);      } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {        NSLog(@"失败->%@",error);      }];  }@end

原标题:IOS 网络浅析-(十一 三方 AFNetworking3.0简介)

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。