I am using following code to display a toast after Facebook authentication
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”);
and NSLog(@"Facebook 2”);
are executing and printing logs respectively. However, toast statement in between these two logs delays and displays after 15-20 seconds.
If I put toast statement [[Toast shared] showToast:self.view withText:@"You disabled your app from settings."];
out of following completion handler:
[accountStore requestAccessToAccountsWithType:fbAcc options:dictFB completion:^(BOOL granted, NSError *error) {
}];
It works fine and displays toast timely, never delays. Any solution to remove the delay?
I believe what EDUsta said is correct. Try calling the toast message on the main thread. All UI changes should be handled on the main thread to avoid weird bugs. Try this:
[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”);
}
}];