【问题标题】:View showing up with delay after Facebook AuthenticationFacebook 身份验证后视图显示延迟
【发布时间】:2017-02-09 12:54:46
【问题描述】:

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

它工作正常,显示吐司及时,从不延迟。有什么办法可以消除延迟?

【问题讨论】:

  • 我假设 requestAccess... 正在异步工作,而 showToast: 是一个 UI 作业,因此您可能需要在主线程中显式调用 showToast: - 如果还没有 -。跨度>
  • @EDUsta 是的,我在主线程中调用了它,它工作正常。谢谢

标签: ios objective-c facebook toast


【解决方案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”);
                        }

                        }];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 2021-08-25
    • 2023-04-06
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 2018-02-24
    相关资源
    最近更新 更多