在Facebook身份验证后查看显示延迟

时间:2017-02-09 12:54:47

标签: ios objective-c facebook toast

我使用以下代码在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) {
}];

它工作正常,及时显示吐司,从不延迟。任何消除延迟的解决方案?

1 个答案:

答案 0 :(得分:1)

我相信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”);
                        }

                        }];