简体   繁体   中英

Facebook Unity Auto Login

Ok so managed to solve this issue, although I'm not able to say for sure what the cause was, I have near enough re-written the init, login, and permission checking parts of our facebook connection class. I couldn't see any obvious difference from the flow we used to that of the example but clearly there was something. In any case auto login on init now seems to work just fine.

Using version 4.3.6 of the Facebook plugin for Unity. Noticing a bit of a bug which is a bit of an annoyance at the moment.

Once the user has logged in, and accepted our permissions, the game continues and posts as desired. However if the game closes and then restarts, the user has to log in again.

Now let me be clear here, we are not currently calling the log in function when we start up again, why? because that causes the momentary app switch which looks horrible and is jarring. The tooltips seem to suggest that the Init should attempt to restart with valid session data. However prior to and after calling that init function, the Access token seems to be blank. So there is no automatic login occurring.

I've tried setting that status flag to true in both the settings object, and by init via code. Neither seem to make a difference.

Is there something I'm missing to get this working?

IS there a way with this official plugin to get the auto login without the app swap at all even? or am I just chasing dreams on that one?

Edit:
Just to provide some extra information on this. Testing currently on an iPhone5 and an iPad3 both with facebook installed, one using a facebook account signed in via the iOS settings, both follow the same behaviour, no session resume on init, and login after init causes the app swap. I'm going to try and test just a blank project with the facebook examples later today to see if this is something we're messing up or if its the plugin.

I know you have solved your problem, but I thought this might be useful for others as I was having similar issues.

FacebookSettings > FB.Init() Parameters > Status should be set to "true". The reference docs on the Status property say:

If true, attempts to initialize the Facebook object with valid session data.

  • Note: this often requires an asynchronous read operation, and any code that depends on its being completed should be synchronized in the HideUnityDelegate passed into Init().

Perhaps it's a mistake in the documentation, but I don't think HideUnityDelegate is actually used in Init() (Unity is not hidden when calling Init). However, the InitDelegate is used, so you can put your login code there.

Example:

void Start() {
    FB.Init(OnInitComplete, OnHideUnity, null);
}

void OnInitComplete() {
    if (FB.IsLoggedIn) {
        Debug.Log("FB Logged in during Init");
    }
    else {
        Debug.Log("FB NOT Logged in during Init");
    }
}

void OnHideUnity(bool unityIsHidden) {
}

Turns out when calling the OnInitComplete method you pass on to the FB.Init method, the variable FB.IsLoggedIn isnt set up yet. After I added a 0.5 delay it now properly finds the logged user. Dunno why its like that on the newer version but it works for me :)

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