自定义Facebook注销按钮在IOS中无效

时间:2014-08-07 06:15:48

标签: ios facebook sdk logout

我是IOS的新手,我使用Facebook SDK为我的应用创建了一个Facebook自定义登录和注销按钮。登录按钮按预期工作,但当我单击我的注销按钮时,它会在我重定向到它时提供登录页面。然后,当我再次尝试登录时,它不会显示Facebook登录UI。但是当我退出我的Facebook应用程序并尝试登录我的应用程序时,登录UI运行良好。这是我的退出按钮。

- (IBAction)btnClicked:(id)sender {

    [FBSession.activeSession closeAndClearTokenInformation];
    NSLog(@"log out");
    LoginUIViewController *loginController1= [[LoginUIViewController alloc] initWithNibName:@"LoginUIViewController" bundle:nil];
      [self presentViewController:loginController1 animated:YES completion:nil];

}

我是否需要在视图控制器中实现注销按钮,或者FB SDK是否自行提供注销功能?

@ Vinod Jat ,,     我在appDelegate中进行了以下更改..

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        // Whenever a person opens the app, check for a cached session
        if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {

            // If there's one, just open the session silently, without showing the user the login UI
            [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
                                               allowLoginUI:NO
                                          completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
    [self sessionStateChanged:session state:state error:error];
     }];
        }

      return YES;

    }

    //This method will handle ALL the session state changes in the app
    - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
    { 
        // If the session was opened successfully
        if (!error && state == FBSessionStateOpen){
            NSLog(@"Session opened");

            return;
        }
        if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
            // If the session is closed
            NSLog(@"Session closed");

        }
    .........
    }


 **In my loginUIViewController I have added following method..**

- (IBAction)FbloginButton:(id)sender {
    NSLog(@"inside login button");

        [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
                                           allowLoginUI:YES
                                      completionHandler:
         ^(FBSession *session, FBSessionState state, NSError *error) {
             NSLog(@"inside login button2");

             // Retrieve the app delegate
             TNLAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
             // Call the app delegate's sessionStateChanged:state:error method to handle session state changes
            [appDelegate sessionStateChanged:session state:state error:error];
              NSLog(@"inside login button3");
         }];
  //redirect to now playing page
    NowPlayingViewController *nowPlaying= [[NowPlayingViewController alloc] initWithNibName:@"NowPlayingViewController" bundle:nil];
    [self presentViewController:nowPlaying animated:YES completion:nil];

}

0 个答案:

没有答案