iOS开发AFNetWorking 的同步,异步请求方法

释放双眼,带上耳机,听听看~!

 

  • 异步请求
 NSString *urlStr = @"****************";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
NSLog(@"----requestData:%@",responseObject);
NSArray *dataInfo = responseObject[@"data"];
for (NSDictionary *dic in dataInfo) {
PlayerModel *model = [[PlayerModel alloc]initWithDictory:dic];
[_data addObject:model];
}
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
//
NSLog(@"---requesterror:%@",error);
}];
  • 同步请求

NSString *urlStr = @"********************************";
AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
NSMutableURLRequest *request = [requestSerializer requestWithMethod:@"GET" URLString:urlStr parameters:nil error:nil];
AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
AFHTTPResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];
[requestOperation setResponseSerializer:responseSerializer];
[requestOperation start];
[requestOperation waitUntilFinished];
NSDictionary *userInfo = [requestOperation responseObject];
NSLog(@"-userInfo-%@",userInfo);
if (userInfo != nil) {
NSArray *dataInfo = userInfo[@"data"];
for (NSDictionary *dic in dataInfo) {
PlayerModel *model = [[PlayerModel alloc]initWithDictory:dic];
[_data addObject:model];
}
[self.tableView reloadData];
}

 

人已赞赏
iOS文章

iOS开发TableViewCell的复用出现数据重复的解决方法

2020-5-6 10:16:55

iOS文章

iOS开发sqlite终端输入指令

2020-5-6 11:32:19

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索