我这样做了,FB 会自动重新创建会话。如果 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];
}];
}
}