Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't just call <code>accountTypeWithAccountTypeIdentifier</code> to access the FB account, you need to supply properties. This needs to be done using <code>requestAccessToAccountsWithType:options:completion:</code> and has an asynchronous response.</p> <p>Move your backup web based auth into a different method, then, check if you can create the account store as you are. If not, call the web method. If you can, try to gain access to the FB account with <code>requestAccessToAccountsWithType:options:completion:</code>. In the completion block you will either have been granted access or you will call the web method.</p> <p>This code should all run on the main thread. The asynchronous response may be called on a different thread so switch back to the main thread to complete your handling.</p> <hr> <p>Fill in the <code>...</code> parts.</p> <pre><code>- (void)webAuthorise {...} - (void)authorise { if(!_accountStore) _accountStore = [[ACAccountStore alloc] init]; ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; if (facebookTypeAccount == nil) { NSLog(@"Failed, No account"); [self webAuthorise]; return; } [_accountStore requestAccessToAccountsWithType:facebookTypeAccount options:@{ACFacebookAppIdKey: @"...", ACFacebookPermissionsKey: @[@"email"]} completion:^(BOOL granted, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ if(granted){ NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount]; _facebookAccount = [accounts lastObject]; NSLog(@"Success"); [self ...]; } else { NSLog(@"Failed, Error: %@", error); [self webAuthorise]; } }); }]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload