使用NSURLSession的步骤:
第一步 通过NSURLSession的实例创建task
第二步 执行task
- (void)NSURLSessionRequest
{
//创建URL
NSString *URLPath = @"https://xxxx";
NSURLSession *sharedSession = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [sharedSession dataTaskWithURL:[NSURL URLWithString:URLPath] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *contentDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSError *merror = nil;
self.successModel = [MTLJSONAdapter modelOfClass:[AWESuccessModel class] fromJSONDictionary:contentDictionary error:&merror]; // 2
self.postsModels = self.successModel.successInfo.posts;
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView