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];
});
}
}];
I check account count before I gain access to it.
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.