ios - Substantial time to push UIViewController in Twitter completion block -


when running code...

-(ibaction)loginwithtwitter:(id)sender { nslog(@"logging in twitter"); acaccountstore *accountstore = [[acaccountstore alloc]init]; acaccounttype *accounttype = [accountstore accounttypewithaccounttypeidentifier:acaccounttypeidentifiertwitter];  [accountstore requestaccesstoaccountswithtype:accounttype options:nil completion:^(bool granted, nserror *error) {     if (error) {         [self showerror:error];         return;     }      if (granted) {         nsarray *accountsarray = [accountstore accountswithaccounttype:accounttype];          if ([accountsarray count] > 1) {             nslog(@"multiple twitter accounts");         }          acaccount *twitteraccount = [accountsarray objectatindex:0];         nslog(@"%@", twitteraccount);          [self pushmaincontroller];     } }]; } 

there 5-10 second delay before pushmaincontrolleris called, though account information logged (after pre-authorization). if move pushmaincontroller call after block however, happens immediately, problem being user isn't logged in @ point. understand can take second block have response due variables such network connectivity, can me understand this?

the completion block not being done on main queue. need ensure ui code gets done on main thread:

[accountstore requestaccesstoaccountswithtype:accounttype options:nil completion:^(bool granted, nserror *error) {     if (error) {         [self showerror:error];         return;     }      if (granted) {         nsarray *accountsarray = [accountstore accountswithaccounttype:accounttype];          if ([accountsarray count] > 1) {             nslog(@"multiple twitter accounts");         }          acaccount *twitteraccount = [accountsarray objectatindex:0];         nslog(@"%@", twitteraccount);          dispatch_async(dispatch_get_main_queue(), ^{             [self pushmaincontroller];         });     } }]; 

you may have wrap showerror call well.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -