Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View showing up with delay after Facebook Authentication

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?

like image 880
Mughees Musaddiq Avatar asked Nov 09 '22 02:11

Mughees Musaddiq


1 Answers

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

                        }];
like image 89
Solsma Dev Avatar answered Nov 14 '22 22:11

Solsma Dev