Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Facebook Login access token error: Falling back to loading access token from NSUserDefaults because of simulator bug

After configuring it based on the instructions I keep on getting this error and I am unable to successfully use Facebook Login on my app. I am running it on XCode 8.1 and using an iOS 10.1 simulator.

I followed the steps on the Facebook iOS SDK guide and put the Facebook login button in my view controller. I displayed the NSUserdefaults and one of the keys is "com.facebook.sdk:serverConfiguration" so I believe it is saving there.

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([FBSDKAccessToken currentAccessToken]) {
        // User is logged in, do work such as go to next view controller.
        NSLog(@"test");
    }
    else {
        FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
        loginButton.center = self.view.center;
        [self.view addSubview:loginButton];
    }
    _loginButton.readPermissions =
    @[@"public_profile", @"email", @"user_friends"];
    NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
}
like image 405
SabCo Avatar asked Oct 29 '22 15:10

SabCo


1 Answers

If the problem is that the iOS Simulator is signed out after a restart of the app, this is caused by a bug in the Facebook SDK. It prevents the simulator from caching the access token.

You can fix this by adding the following line:

key = [NSString stringWithFormat:@"%@_fix", key];

in FBSDKKeychainStore.m:94 and FBSDKKeychainStore.m:135 just before:

[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];

like image 168
Jorn van Dijk Avatar answered Nov 15 '22 00:11

Jorn van Dijk