我只是在检查FBSession的状态
- (BOOL)hasValidSession {
return (self.session.state == FBSessionStateOpen)
}
有时候状态会暂时改为FBSessionStateOpenTokenExtended,这会返回NO,这会导致我的登录模式失效。当我再次点击连接时,它会使应用程序崩溃以尝试重新建立活动的facebook会话。所以我把它改成了
- (BOOL)hasValidSession {
if (self.session.state == FBSessionStateOpen || self.session.state == FBSessionStateOpenTokenExtended) {
return YES;
}
else {
return NO;
}}
我的上述方法到目前为止工作但似乎是一个黑客...在您的应用中检查有效会话的最佳无处不在的方法是什么?
答案 0 :(得分:3)
这是我在我的应用中查看facebook会话的方式,它对我有用:
-(BOOL)checkFacebookSession
{
if([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded)
{
NSLog(@"Logged in to Facebook");
[self openFacebookSession];
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc] initWithTitle:@"Facebook" message:@"You're already logged in to Facebook" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertDialog show];
[alertDialog release];
return YES;
}
else{
NSLog(@"Not logged in to Facebook");
return NO; //Show login flow.
}
}
希望它有所帮助! :d
答案 1 :(得分:0)
如果状态位于FBSessionStateOpen
或FBSessionStateOpenTokenExtended
,则会话处于活动状态。您可以使用以下方法获取用户的当前状态:
- (BOOL)isActiveSession
{
return (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended);
}