1.dispatch_group_t实现所有请求全部结束后调用方法
dispatch_group_t myGroup = dispatch_group_create();
dispatch_group_enter(myGroup);
void(^myBlock)() = ^(){
NSLog(@"第一个任务");
dispatch_group_leave(myGroup);
};
myBlock();
dispatch_group_enter(myGroup);
void(^myBlock2)() = ^(){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"第二个任务");
dispatch_group_leave(myGroup);
});
};
myBlock2();
dispatch_group_notify(myGroup, dispatch_get_main_queue(), ^{
NSLog(@"上面两个都结束!");
});