View delayed readings after Facebook authentication

I use the 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"); run and print magazines respectively. However, the toast expression between the two logs is delayed and displayed after 15-20 seconds.

If I put the toast operator [[Toast shared] showToast:self.view withText:@"You disabled your app from settings."]; from the following completion handler:

 [accountStore requestAccessToAccountsWithType:fbAcc options:dictFB completion:^(BOOL granted, NSError *error) { }]; 

It works great and displays a toast in a timely manner, never lingers. Any solution to fix the delay?

+5
source share
1 answer

I believe EDUsta said the right thing. Try calling a toast message in the main thread. All user interface changes should be handled in the main thread to avoid strange errors. Try the following:

 [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"); } }]; 
+1
source

Source: https://habr.com/ru/post/1264015/


All Articles