前幾天發現iOS九、xcode7以後NSURLConnection的API被棄用了,取而代之的是NSURLSession,看到這我首先想到了AFNetworking,由於工程的全部網絡請求都是基於AF又封裝的。因此立馬去Cocoapods裏邊搜索AFNetworking,結果發現如今都3.0.4版本了,下邊是最新的AFNetworking GET請求的寫法:html
- 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);
- }];