如何在同一個方法中的語句之前異步執行塊?以相同方法在語句之前異步執行塊
返回總是塊之前執行,但如果提交恆等於
號我想座返回之前執行。 我該怎麼辦? 我嘗試dispatch_semaphore_t
,但checkVerifyCode
在主線程中。 我無法阻止主線程。
-(BOOL)checkVerifyCode
{
__block BOOL commit = NO;
[SMSSDK commitVerificationCode:self.verificationNum.text phoneNumber:self.phoneNumber.text zone:@"86" result:^(NSError *error) {
if (error) {
NSString *errInfo = [error.userInfo objectForKey:@"commitVerificationCode"];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[hud setMode:MBProgressHUDModeText];
[hud setLabelText:@"驗證碼輸入錯誤"];
[hud setLabelText:errInfo];
hud.color = [UIColor clearColor];
hud.labelColor = [UIColor colorWithRed:118/255.f green:214/255.f blue:255/255.f alpha:0.8f];
hud.detailsLabelColor = [UIColor colorWithRed:118/255.f green:214/255.f blue:255/255.f alpha:0.8f];
hud.margin = 10.f;
hud.yOffset = -100.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:3];
NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:commit] forKey:@"bool"];
[self performSelectorOnMainThread:@selector(setCommit:) withObject:dict waitUntilDone:NO];
}else
{
NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:commit] forKey:@"bool"];
[self performSelectorOnMainThread:@selector(setCommit:) withObject:dict waitUntilDone:NO];
commit = YES;
}
}];
return commit;
}
爲了讓你的問題得到正確的答案,請你澄清一下,如果方法checkVerifyCode的調用者線程與線程結果相同:^(){...}塊被調用,或者這些線程是不同的。 – DisableR