以前遇到的需求(見(jiàn)標(biāo)題)钮糖,自己實(shí)現(xiàn)了一下,貼上代碼枢析。包含了完整請(qǐng)求過(guò)程玉掸,拿來(lái)黨請(qǐng)拿走。
#pragma mark? - 點(diǎn)擊活動(dòng)按鈕登疗,檢測(cè)兩個(gè)活動(dòng)是否都是開(kāi)放狀態(tài)
-(void)checkIfActivitiesAreOn{
? ? __weak typeof(self)weakSelf = self;
? ? //信號(hào)量
? ? dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
? ? //創(chuàng)建全局并行
? ? dispatch_group_t group = dispatch_group_create();
? ? dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
? ? //網(wǎng)絡(luò)請(qǐng)求一
? ? dispatch_group_async(group, queue, ^{
? ? ? ? [weakSelfpostActivityDailyInfoRequest:^{
? ? ? ? ? ? dispatch_semaphore_signal(semaphore);
? ? ? ? }];
? ? });
? ? //網(wǎng)絡(luò)請(qǐng)求二
? ? dispatch_group_async(group, queue, ^{
? ? ? ? [weakSelfpostActivityWheelFortuneRequest:^{
? ? ? ? ? ? dispatch_semaphore_signal(semaphore);
? ? ? ? }];
? ? });
? ? dispatch_group_notify(group, queue, ^{
? ? ? ? dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
? ? ? ? dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{
? ? ? ? ? ? if (weakSelf.treasureChestActivityIsOn && weakSelf.turnTableActivityIsOn) {
? ? ? ? ? ? ? ? GBActivityMainView *view = [GBActivityMainView invitationUpdateAppView];
? ? ? ? ? ? ? ? [viewshowFillInvitationUpdateAppView];
? ? ? ? ? ? }
? ? ? ? });
? ? });
}
#pragma mark - 獲取活動(dòng)1
- (void)postActivityDailyInfoRequest:(void(^)())finish
{
//? ? finish();
? ? __weak typeof(self)weakSelf = self;
? ? GBActivityDailyInfoRequest *req = [GBActivityDailyInfoRequest new];
? ? req.token = [GBFacade sharedInstance].currentUserInfo.token;
? ? [reqstartRequest:^(BOOLsuccess,HttpReqResult*result) {
? ? ? ? if(success){
? ? ? ? ? ? GBActivityDailyInfoDataInfo *info = result.resultObj[KEY_OBJECT];
? ? ? ? ? ? if(info.status==1) {// 0未開(kāi)始排截,1進(jìn)行中嫌蚤,2已結(jié)束
? ? ? ? ? ? ? ? weakSelf.treasureChestActivityIsOn=true;
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? weakSelf.treasureChestActivityIsOn=false;
? ? ? ? ? ? }
? ? ? ? }else{
? ? ? ? ? ? weakSelf.treasureChestActivityIsOn = false;
? ? ? ? }
? ? ? ? finish();
? ? }];
}
#pragma mark - 獲取活動(dòng)2
- (void)postActivityWheelFortuneRequest:(void(^)())finish
{
? ? __weak typeof(self)weakSelf = self;
? ? GBActivityWheelFortuneInfoRequest *req = [GBActivityWheelFortuneInfoRequest new];
? ? req.token = [GBFacade sharedInstance].currentUserInfo.token;
? ? [reqstartRequest:^(BOOLsuccess,HttpReqResult*result) {
? ? ? ? if(success){
? ? ? ? ? ? GBActivityWheelFortuneInfoDataInfo *info = result.resultObj[KEY_OBJECT];
? ? ? ? ? ? if(info.status==1) {// 0未開(kāi)始,1進(jìn)行中断傲,2已結(jié)束
? ? ? ? ? ? ? ? weakSelf.turnTableActivityIsOn=true;
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? weakSelf.treasureChestActivityIsOn=false;
? ? ? ? ? ? }
? ? ? ? }else{
? ? ? ? ? ? weakSelf.treasureChestActivityIsOn = false;
? ? ? ? }
? ? ? ? finish();
? ? }];
}