Facebook会话结束

时间:2014-01-09 11:01:55

标签: ios facebook session facebook-login

我正在iOS应用中实现Facebook登录。我认为它实施得很好,但我有一个问题。我在应用程序的设置下运行登录。当我离开应用程序然后当我回来时,如果我想使用Facebook操作(即分享照片),我无法这样做,因为会话已关闭。当我进入设置菜单,我在登录按钮时,会话重新打开而不再执行登录(只需将我指向视图登录按钮,然后会话再次打开)。

因此,我需要活动会话而用户没有(总是)进入设置菜单。有什么建议吗?

由于

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题:

必须制作

  

@property(强大,非原子)FBSession *会话;

AppDelegate中的

in

  
      
  • (void)applicationDidBecomeActive:(UIApplication *)application {   [FBAppEvents activateApp];   [FBAppCall handleDidBecomeActiveWithSession:self.session]; }
  •   

  
      
  • (void)applicationWillTerminate:(UIApplication *)application {[self.session close]; }
  •   

  
      
  • (BOOL)应用程序:(UIApplication *)应用程序           openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication        注释:(id)注释{   return [FBAppCall handleOpenURL:url                 sourceApplication:sourceApplication                       withSession:self.session]; }
  •   

在您的设置类

  

if(appDelegate.session.isOpen)           {

        [FBSession setActiveSession:appDelegate.session];
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection,
     

NSDictionary * user,NSError * error)                {                    [self registerationWithFBRequestConnection:connection andFBGraphUser:user andNSError:error];                }];

    }
    else
    {
        [appDelegate.session closeAndClearTokenInformation];
        NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
        appDelegate.session = [[FBSession alloc] initWithPermissions:permissions];
        [FBSession setActiveSession:appDelegate.session];

        [appDelegate.session openWithBehavior:(FBSessionLoginBehaviorWithFallbackToWebView)
     

completionHandler:^(FBSession * session,FBSessionState status,NSError   *错误)                {                    [self sessionStateChangedWithFBSession:session andFBSessionState:status andNSError:error];                }];

    }
     
      
  • (void)sessionStateChangedWithFBSession:(FBSession *)session andFBSessionState:(FBSessionState)status andNSError:(NSError *)error {   开关(状态)   {       case FBSessionStateOpen:       {[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection * connection,   NSDictionary * user,NSError *错误)            {

             [self registerationWithFBRequestConnection:connection andFBGraphUser:user andNSError:error];
         }]; }
        break;
    case FBSessionStateClosed:
    
        break;
    case FBSessionStateClosedLoginFailed:
    
        break;
    default:
        break;
    
         

    }}   在您的registerationWithFBRequestConnection:方法中,您应该处理它..在“设置”中获取有关用户的所有信息。

  •