我有一个应用程序,用户可以选择登录到FB.我的代码主要基于FB的教程,大多数情况下,应用程序和FB集成按预期工作.我遇到的问题是应用程序没有记住从启动到启动用户已选择将应用程序连接到FB.我检查AppDelegate.m以检查缓存的FBSession:
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) { // Yes,so just open the session (this won't display any UX). NSLog(@"The state is IS 'State created token loaded'"); [self openSessionWithAllowLoginUI:NO]; } else { // No,display the login page. NSLog(@"The state is NOT 'State created token loaded'"); [self openSessionWithAllowLoginUI:YES]; }
每次启动应用程序时,控制台中都会显示“状态为非’状态创建令牌已加载’”行.这让我觉得我没有做正确的事情,以使FB登录从发布到发布持续存在.
我真的可以在这里使用一些建议.在应用程序启动时,确保“FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded”为真,需要做什么?
解决方法
如果您在应用启动时拥有此代码,请注意:
FBSession.activeSession
可能还没有设定.您要检查缓存令牌的目的是:
if (![self openSessionWithAllowLoginUI:NO]) { [self openSessionWithAllowLoginUI:YES]; }
如果存在缓存的令牌,则使用“NO”的第一个调用将同步返回值true.如果没有缓存的令牌,则返回no.此时,您可以强制登录UX发生.