前几天发现iOS9、xcode7之后NSURLConnection的API被弃用了,取而代之的是NSURLSession,看到这我首先想到了AFNetworking,因为工程的所有网络请求都是基于AF又封装的。所以立马去Cocoapods里边搜索AFNetworking,结果发现现在都3.0.4版本了,下边是最新的AFNetworking GET请求的写法:
- AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
- sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
- [sessionManager GET:kFirstPageList parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
- NSLog(@"%lld", downloadProgress.totalUnitCount);
- } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSLog(@"%@", responseObject);
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- NSLog(@"%@",error);
- }];