我正在使用FBSDKLoginManager在我的应用程序中实现Facebook登录.
Facebook docs似乎暗示这会为后续应用程序启动保存令牌,以便用户不必每次都登录:
The FBSDKLoginManager sets this token for you and when it sets currentAccessToken it also automatically writes it to a keychain cache.
我一直试图在应用程序启动时从所述缓存中检索此令牌,或者如果找不到则显示我的应用程序的Facebook登录屏幕:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FBSDKProfile enableUpdatesOnAccessTokenChange:YES]; if ([FBSDKAccessToken currentAccessToken]) { // user is logged in,continue to app's main screen } else { // show login screen } //... }
解决方法
您需要调用“[[FBSDKApplicationDelegate sharedInstance]应用程序:application didFinishLaunchingWithOptions:launchOptions]”在尝试获取缓存令牌之前.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
…