Search code examples
facebookfacebook-ios-sdk

FBSession.activeSession handleOpenURL fails after app jettisoned, restarted


My iOS app is frequently jettisoned during FUS to the Facebook login page. I'm working on reducing memory usage but I'd like to guarantee the login works even if my app is jettisoned.

So far, though, I can't get this to work. When I press the Login button, my app re-launches successfully. I get the url passed into didFinishLaunchingWithOptions as well as my appDelegate's openURL, and I call [[FBSession alloc] initWithAppID] which returns a session in the SessionCreated state.

Then I call

openActiveSessionWithPermissions:array allowLoginUI:NO completionHandler:^{stuff}

But when I call handleOpenURL on the active session, my completionHandler is not called and I am not logged in.

Can someone help me with how to get the FB SDK ready to accept the returned URL? Or is this even possible?

I'm using v3.8.0 of the FB SDK.


Solution

  • Finally figured out the correct sequence of calls. authStr is the url passed into didFinishLaunchingWithOptions.

    bool IOSFacebookDriver::OpenAuthToken(const std::string &authStr)
    {
        NSString *authString = [NSString stringWithCString:authStr.c_str() encoding:NSUTF8StringEncoding];
        NSURL *authURL = [NSURL URLWithString:authString];
        FBAccessTokenData *token = [FBAccessTokenData createTokenFromFacebookURL:authURL appID:mNSAppId urlSchemeSuffix:[FBSession defaultUrlSchemeSuffix]];
        bool tokenAccepted = [[FBSession activeSession] openFromAccessTokenData:token completionHandler:^(FBSession* session, FBSessionState state, NSError* error)
         {<completion handler>};
    }