我使用以下代码在Facebook身份验证后显示吐司
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) // check Fb is configured in Settings or not
{
accountStore = [[ACAccountStore alloc] init]; // you have to retain ACAccountStore
ACAccountType *fbAcc = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = @"xxxxx";
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];
[accountStore requestAccessToAccountsWithType:fbAcc options:dictFB completion:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(@"Perform fb registration");
} else {
NSLog(@"Facebook 1”);
[[Toast shared] showToast:self.view withText:@"You disabled your app from settings."];
NSLog(@"Facebook 2”);
}
}];
}
NSLog(@"Facebook 1”);
和NSLog(@"Facebook 2”);
分别执行和打印日志。但是,这两个日志之间的 toast 语句会在 15-20 秒后延迟和显示。
如果我将 toast 语句[[Toast shared] showToast:self.view withText:@"You disabled your app from settings."];
以下完成处理程序中:
[accountStore requestAccessToAccountsWithType:fbAcc options:dictFB completion:^(BOOL granted, NSError *error) {
}];
它工作正常,及时显示吐司,从不拖延。有什么解决方案可以消除延迟吗?
我相信EDUsta说的是正确的。尝试在主线程上调用 Toast 消息。所有 UI 更改都应在主线程上处理,以避免奇怪的错误。试试这个:
[accountStore requestAccessToAccountsWithType:fbAcc options:dictFB completion:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(@"Perform fb registration");
} else {
NSLog(@"Facebook 1”);
dispatch_async(dispatch_get_main_queue(), ^{
[[Toast shared] showToast:self.view withText:@"You disabled your app from settings."];
});
NSLog(@"Facebook 2”);
}
}];