Search code examples
iphoneobjective-ciosfbconnect

Problems with fbDidLogin never called iOS


I'm having problems with my app saving the access_token. The problem is, when an iPhone hasn't the Facebook app installed, safari will handle this and there is no problem. But as soon as the iPhone has the Facebook app installed. It Just isn't saving the access token and opens the Facebook app every time when it needs to do something with Facebook. It then says, you already have given .... permission...

This is what i'm doing to in the viewdidload to ask permission the first time and receive the access token from the user defaults:

facebook = [[Facebook alloc] initWithAppId:@"APPID"];


    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    NSArray* permissions =  [[NSArray arrayWithObjects:
                              @"read_stream", @"offline_access", nil] retain];

    if (![facebook isSessionValid]) {
        [facebook authorize:permissions delegate:self];
    }

This is what i'm doing in the fbdidlogin:

- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];   
}

But for some way when the Facebook app takes control this just doesn't work...It wil doe authorize every time when the view did load, loads again.

Has anyone got a clue?

Thnx!

btw: I also have the following line:

(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [[controller facebook] handleOpenURL:url]; }

Solution

  • I've found a workaround, which imo is better the using the Facebook app. In the Facebook.m file i've changed this:

      [self authorizeWithFBAppAuth:YES safariAuth:YES];
    

    to this

      [self authorizeWithFBAppAuth:NO safariAuth:YES]; 
    

    In this case users don't leave the app, and everything is handled within the popup without using the Facebook app.