AFNNetworking2.0版本的使用
虽然是2.0版本了,但是使用的方法还是老的方法了,请求网络也能够成功,符合我的程序规范就Ok了
好了,废话不多说,直接上代码
NSString *urlString = @"http://www.XXXXX.com/getmessage.php"; __block NSMutableArray *result; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; NSMutableDictionary *dictM = [NSMutableDictionary dictionary]; [dictM setObject:@"json" forKey:@"format"]; [manager GET:urlString parameters:dictM success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"%@",responseObject); if (result == nil) { result = [NSMutableArray array]; } NSArray *array = responseObject; for (NSDictionary *dict in array) { PublicMessage *publicMessage = [[PublicMessage alloc]init]; publicMessage.ID = [[dict objectForKey:@"id"]integerValue]; publicMessage.username = [dict objectForKey:@"username"]; publicMessage.title = [dict objectForKey:@"title"]; publicMessage.content = [dict objectForKey:@"content"]; publicMessage.good = [dict objectForKey:@"good"]; publicMessage.bad = [dict objectForKey:@"bad"]; publicMessage.time = [[dict objectForKey:@"time"]integerValue]; PublicMessage *public = [[DBManager sharedDBManager]findPublicMessageById:publicMessage.ID]; if (public == nil) { // 说明没有插入到数据库的数据 [[DBManager sharedDBManager]createPublicMessage:publicMessage]; } else { // 更新该条的共有数据信息 [[DBManager sharedDBManager]updatePublicMessageWithPublicMessage:publicMessage]; } } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"请求网络失败=---%@",error.localizedDescription); }];