Edit: No work around yet, but Facebook in there own SDK seemed to have deprecated using the system FB sign-on. I tried the latest SDK, and it just completely ignores the system sign-on. Unfortunately I can' used the latest SDK as, despite using the "legacy" setting, it still returns a token which doesn't give me what I need. It might be useful to see how they're bypassing the system settings though!
Original Q
I have an app which is using Facebook to authenticate.
I'm using the Facebook SDK (3.13.1 - the last pre api v2 version)
If I attempt to authenticate, as long as I don't have a FB account setup in the system settings, everything works fine. The app launches either the FB mobile app or mobile Safari to login an prompts me to grant the necessary permissions.
As soon as there is a system account setup, it fails silently. I'm deleting the app in between runs to ensure that the lack of permissions isn't persisting. If I run some of the FB sample apps which come with the SDK, they prompt for permission just fine, so it is obviously a problem with my app or the configuration of the Facebook app.
I've looked at these 2 similar questions:
Facebook Login - If user account is present (and app is not installed) login fails
Facebook Login error when facebook account is already configured in system preferences
but neither provides an answer that works in my situation. (E.g I do have bundle identifiers configured in the Facebook App)
I've tried using my own custom login code (based on the Facebook guide) and using the FBLoginView, both with the same effect.
I've also tried using ACAccountStore to make the request directly to the system store, with the same effect. Any ideas?
I'll include some code, but I'm fairly certain the code is not the problem - it all works fine if the system FB account is not configured: (i've changed my FacebookAppIDkey here)
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{ ACFacebookAppIdKey: @"123",
ACFacebookPermissionsKey: @[@"public_profile", @"user_likes", @"user_friends", @"email"],
ACFacebookAudienceKey: ACFacebookAudienceFriends};
[accountStore requestAccessToAccountsWithType:facebookType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [accountStore
accountsWithAccountType:facebookType];
id facebookAccount = [accounts lastObject];
DLog(@"%@", facebookAccount);
}
else
{
if (error)
{
DLog(@"%@", error.localizedDescription);
}
}
}];
Using the SDK:
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_likes", @"user_friends", @"email"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
AppDelegate* appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
[appDelegate sessionStateChanged:session state:state error:error];
if ([FBSession activeSession].isOpen) {
__typeof__(self) strongSelf = weakSelf;
strongSelf.facebookToken = session.accessTokenData.accessToken;
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
completion(error,(NSDictionary *)result);
}];
} else {
completion(error,nil);
}
}];