7

I'm using Facebook's iOS SDK 3.7 on my iOS app to handle logins. When I request post permissions it looks like the expiration date is about 2 months from the date of login.

I understand I can check the expiration date using [FBSession activeSession].accessTokenData.expirationDate but what happens, and how do I handle the token when the token expires?

Do I run [FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:]; again?

Jiho Kang
  • 2,482
  • 1
  • 28
  • 38
  • 1
    The quick answer is, don't worry about it, the SDK takes care of renewing your tokens for you. – Ming Li Aug 20 '13 at 18:12

1 Answers1

0

I do this and FB recreates the session automatically. If FB has changed terms of use or something, then it shows login dialog to the user.

// call this before any calls to FB api
- (void)openSession
{
 if(FBSession.activeSession.state != FBSessionStateOpen)
{

    [FBSession openActiveSessionWithPublishPermissions:@[FB_PUBLISH_ACTIONS_PREMISSION]
                                       defaultAudience:FBSessionDefaultAudienceFriends
                                          allowLoginUI:NO
                                     completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                    if(!error && session.isOpen)
                    {
                    }
                    else
                    {
                        _lastError = error;
                        // handle the error
                    }
                       // here, you can handle the session state changes in switch case or
                      //something else
                    [self session:session
                  hasChangedState:status
                        withError:error];

                }];
        }
}
Basheer_CAD
  • 4,908
  • 24
  • 36