我在集成Web服务时使用回调方法。任何人都可以建议,我如何平行使用多种回调方法,
我知道我们可以通过创建
来集成多个Web服务dispatch_group_t group = dispatch_group_create();
//block 1
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
[self getUserProfiles];
});
//block 2
dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{
// block 2 will get notify, after block 1 complete his task.
}
但如何使用回调执行上述操作? 任何建议将不胜感激。
答案 0 :(得分:2)
您可以尝试阻止您的目标
创建返回块的方法
-(void)getResponseWithUrl:(NSString *)url AndWithPararameter:(NSDictionary *)parameter WithCallback:(void(^)(BOOL success, id responseObject))callback{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:[NSString stringWithFormat:@"%@%@",BASEURL,url] parameters:parameter progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"%@",responseObject);
callback(YES,responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
callback(NO,nil);
}];
}
以这种方式调用
[self getResponseWithUrl:@"URL" AndWithPararameter:@{@"parameters":@""} WithCallback:^(BOOL success, id responseObject) {
}];