【发布时间】: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