运行此代码时...
-(IBAction)loginWithTwitter:(id)sender {
NSLog(@"Logging in with twitter");
ACAccountStore *accountStore = [[ACAccountStore alloc]init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (error) {
[self showError:error];
return;
}
if (granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 1) {
NSLog(@"Multiple twitter accounts");
}
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSLog(@"%@", twitterAccount);
[self pushMainController];
}
}];
}
在实际调用之前有 5-10 秒的延迟pushMainController
,即使帐户信息几乎立即被记录(在预授权之后)。但是,如果我pushMainController
在块之后移动呼叫,它会立即发生,唯一的问题是用户当时不一定登录。我知道由于网络连接等变量,一个块可能需要一秒钟才能得到响应,但是有人可以帮助我理解这一点吗?