FB.Logout() not working in Facebook UnitySDK

谁说胖子不能爱 提交于 2019-11-29 14:35:42

I believe the FB.Logout operation is asynchronous, and the value of FB.IsLoggedIn would be true immediately after calling FB.Logout(). If you look at the documentation, it says:

You almost certainly should not use this function, which is provided primarily for completeness. Having a logout control inside a game that executes a Facebook-wide logout will violate users' expectations. Instead, allow users to control their logged-in status on Facebook itself.

Actually FB.Logout() has no delegate to let you know that account is successfully logout, so you have to create your own listner.

Secondly it will not sign you out from the actual device Facebook app or browser. If you want to sign in with different account, so you can do by signing out explicitly from the app or browser.

Here is the code for how to detect that if you are logged out. It may useful to show Login and Logout button for Facebook that when to Login or Logout.

Here is the code from that you can determine the user has logged out within the Game.

public void OnFacebookLogout()
{
    if (FB.IsLoggedIn)
    {                                                                                  
        FB.Logout (); 
        StartCoroutine ("CheckForSuccussfulLogout");
    } 
}

IEnumerator CheckForSuccussfulLogout()
{
    if (FB.IsLoggedIn) 
    {
        yield return new WaitForSeconds (0.1f);
        StartCoroutine ("CheckForSuccussfulLogout");
    } else 
    {
    // Here you have successfully logged out.
    // Do whatever you want as I do, I just enabled Login Button and Disabled
    // logout button through this method.
        EnableFacebookLoginButton ();
    }
}

I'm not sure if it is correct but why not just do some while loop?

IEnumerator FBLogout (){
 FB.Logout ();
 while (FB.IsLoggedIn){
  print ("Logging Out");
  yield return null;
 }
 print ("Logout Successful");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!