简体   繁体   English

Facebook Unity自动登录

[英]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. 好的,所以设法解决了这个问题,尽管我不能确定原因是什么,但我已经足够重写了我们Facebook连接类的init,login和权限检查部分。 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. 无论如何,现在在init上自动登录似乎可以正常工作。

Using version 4.3.6 of the Facebook plugin for Unity. 将Facebook插件的4.3.6版本用于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. 工具提示似乎建议Init应该尝试使用有效的会话数据重新启动。 However prior to and after calling that init function, the Access token seems to be blank. 但是,在调用该init函数之前和之后,访问令牌似乎为空。 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. 我尝试在设置对象中以及通过代码通过init将状态标志设置为true。 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. 当前在安装了facebook的iPhone5和iPad3上进行的测试,都使用通过iOS设置登录的facebook帐户进行的测试,两者都遵循相同的行为,init上没有会话恢复,并且在init导致应用交换后登录。 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. 今天晚些时候,我将尝试使用Facebook示例测试一个空白项目,看看这是否是我们搞砸的东西,或者它是否是插件。

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". FacebookSettings> FB.Init()参数> Status应该设置为“ true”。 The reference docs on the Status property say: Status属性的参考文档说:

If true, attempts to initialize the Facebook object with valid session data. 如果为true,则尝试使用有效的会话数据初始化Facebook对象。

  • 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(). 注意:这通常需要异步读取操作,并且取决于它是否完成的任何代码都应该在传递给Init()的HideUnityDelegate中进行同步。

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). 也许这是文档中的错误,但是我不认为HideUnityDelegate实际上是在Init() (在调用Init时,Unity不会被隐藏)。 However, the InitDelegate is used, so you can put your login code there. 但是,由于使用了InitDelegate ,因此您可以在其中放置登录代码。

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. 事实证明,当调用传递到FB.Init方法的OnInitComplete方法时,尚未设置变量FB.IsLoggedIn。 After I added a 0.5 delay it now properly finds the logged user. 在添加0.5延迟后,它现在可以正确找到已登录的用户。 Dunno why its like that on the newer version but it works for me :) 邓诺(Dunno)为什么在更新的版本上会这样,但对我有用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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