我在iOS应用上使用Facebook的iOS SDK 3.7处理登录。当我请求发布权限时,它的到期日期似乎是从登录之日起大约2个月。

我知道我可以使用[FBSession activeSession].accessTokenData.expirationDate检查到期日期,但是会发生什么,当 token 过期时如何处理 token ?

我是否再次运行[FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:];

最佳答案

我这样做,FB会自动重新创建 session 。
如果FB更改了使用条款或其他内容,则会向用户显示登录对话框。

// 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];

                }];
        }
}

10-08 07:23
查看更多