1

I found an weird problem of iOS account setting. When I working on ACAccount renew issue, I found that if users login facebook in device setting after my app in installed, my app will not be able to gain access to facebook account.

To be precise, my app will not be shown on the "ALLOW THESE APPS TO USE YOUR ACCOUNT". Therefore, I've done some tests about this issue:

(1). Facebook login after the app installed -> not shown

(1-1). Remove the app and reinstall -> not shown

(2). Facebook re-login after app installed -> not shown, and all apps which have been granted or not granted will not be shown, too.

(3). Facebook login before the app installed -> shown

And, once the problem encountered, it is not reversible, whether you re-login facebook, reinstall the apps or restart the device will not fix the problem. Only native iOS apps and Facebook app will remain on the list.

There was a old question about this, but the issue is not answered. Anyone encountered the same problem?

Updated 2013.11.20 11:38 AM

I made two mistakes when using ACAccount, following is a sample code of gaining access to facebook account:

    // Check if store exists
if(!_accountStore)
    _accountStore = [[ACAccountStore alloc] init];

ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// Request access, note that one should not check if the account is available until the access right is granted
[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                       options:@{ACFacebookAppIdKey: @"FACEBOOK_API_KEY", ACFacebookPermissionsKey: @[@"read_stream"]}
completion:^(BOOL granted, NSError *error) {
    if(granted){
        NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
        _facebookAccount = [accounts lastObject];
        NSLog(@"Success");
    }else{
        // ouch
        _facebookAccount = nil;
        NSLog(@"Failed, Error: %@", error);
        dispatch_async(dispatch_get_main_queue(), ^{
            NSString *message = [NSString stringWithFormat:@"No facebook account or access denied by user. Error:%@", error];
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"系統提示" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        });
    }

}];
  1. I check account count before I gain access to it.

  2. I am not sure if this is a bug of APPLE SDK, if I request for access of "publish_stream", the request will fail.

Then, I saw discussions of errors about requestAccessToAccountsWithType here. It is said that we should request for permissions twice, one for read, and one for write.

Therefore, I change the access right from "publish_stream" to "read_stream", then, it works. My app is shown on the list again.

Although the request for write permission failed, but it does not affect the ability to post on the user's behave.

Updated 2014.8.12 12:31 AM

maml reported that the permission may still be denied after doing the steps above, but the app did show up in setting which makes it possible to toggle it on.

Community
  • 1
  • 1
Hubert Wang
  • 502
  • 5
  • 17

1 Answers1

0

I had solved the issue in the update of my question. It may seems like a workaround, but currently it did solve the problem. If you want to know detail about the solution, see the edited question above.

To solve the problem, we have to:

  1. Change permission access from "publish_stream" to "read_stream". Though you were request for read permission, you are still able to post to the user's time line.

  2. No further steps.

I think this might be a bug of ACAccount framework. However, it did save our time to study Facebook API. So, if you use this method, remember to keep an eye on this issue, which might be fixed in the future.

Note. I answer my own problem to keep it from becoming Tumbleweed...

Hubert Wang
  • 502
  • 5
  • 17
  • I was experiencing the same thing. I followed your solution. The request for access is still denied but, the app does show up in settings and you can toggle it 'on' there and then are able to post. – maml Jun 19 '14 at 01:09