简体   繁体   中英

Facebook Unity SDK Auto Login not happening?

I have kept the Status flag of FB.Init() as true. Still after I quit my app , FB never logs back again.I have to re-login everytime. Although it says that it'll attempt to relogin from a valid session data. What am I missing here?

Here's the code:

private void CallFBInit()
    {
        FB.Init(OnInitComplete, OnHideUnity);

    }

    private void OnInitComplete()
    {
        if (FB.IsLoggedIn) 
        {
            Debug.Log ("Loggedin userid:  " + FB.UserId);   
            return;
        } 

    }

    private void OnHideUnity(bool isGameShown)
    {
        if (!isGameShown)                                                                        
        {                                                                                        
            // pause the game - we will need to hide                                             
            Time.timeScale = 0;                                                                  
        }                                                                                        
        else                                                                                     
        {                                                                                        
            // start the game back up - we're getting focus again                                
            Time.timeScale = 1;                                                                  
        } 
    }

    private void LoginFB()
    {
        FB.Login("email,public_profile, user_friends", LoginCallback);
    }

    private void LogoutFB()
    {
        if (FB.IsLoggedIn) 
        {
            FB.Logout();

        }
    }


    private void LoginCallback(FBResult result)
    {
        // Call Cognito Login for FB as well
        AWSManager.FacebookLoginCallback (result);

        if (result.Error != null)
        {

        }
        else if (!FB.IsLoggedIn) 
        {

        } 
        else if(FB.IsLoggedIn)
        {


        }

    }

    public void OnClickedOnFBButton()
    {
        //Debug.Log ("clicked on facebook button");
        if(FB.IsLoggedIn)
        {
            return;
        }

        LoginFB ();
    }

EDIT: It's only giving issues on iOS , works fine on Android.

Are u checking the FB.IsLoggedIn after the facebook initialization. From what i see in the code is that the OnClickedOnFBButton() might be called before the fb is actually initialized. So always the FB.IsLoggedIn might return false which calls your loginFB() method again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM