//创建信号量
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// 等待信号量
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
[BadgeCountModel HomeBadgeCountBlock:^(NSDictionary *data) {
NSNumber *num = data[@"num"];
if (num.integerValue > 0 ) {
weakSelf.rightBt.isShowBadge = YES;
} else {
weakSelf.rightBt.isShowBadge = NO;
}
// 发送信号量
dispatch_semaphore_signal(semaphore);
} andError:^(NSError *error) {
dispatch_semaphore_signal(semaphore);
}];
});
dispatch_async(queue, ^{
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
[BadgeCountModel HomeDetailBadgeCountBlock:^(NSArray *data) {
if (!weakSelf.badgeDict) {
weakSelf.badgeDict = [NSMutableDictionary dictionary];
}
[weakSelf.badgeDict removeAllObjects];
NSMutableArray *badgeArray = [NSMutableArray array];
for (NSDictionary *dict in data) {
BadgeCountModel *model = [[BadgeCountModel alloc] init];
model.code = [NSString stringWithFormat:@"%@",dict[@"key"]];
model.value = [NSString stringWithFormat:@"%@",dict[@"value"]];
[badgeArray addObject:model];
NSIndexPath *path = [self getIndexPathWithCode:model.code];
if (!path) {
continue;
}
[weakSelf.badgeDict setObject:model.value forKey:path];
}
[weakSelf.collectionView reloadData];
[[GLMenuManager shareInstance] setRedPointArray:badgeArray];
dispatch_semaphore_signal(semaphore);
} andError:^(NSError *error) {
dispatch_semaphore_signal(semaphore);
}];
网友评论