尽管通过 FBSDKLoginButton 登录,但 ios Facebook SDK v4.x 访问令牌为 null [英] ios Facebook SDK v4.x access token null despite being logged in via FBSDKLoginButton
问题描述
尽管按钮显示我已登录,但我的 facebook 访问令牌为空.有人知道为什么会这样吗?
My facebook access token is null despite the fact that the button shows that I'm logged in. Anyone know why this would be?
来自 RootViewController.m
From RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self->login_button = [[FBSDKLoginButton alloc] init];
self->login_button.center = self.view.center;
[self.view addSubview:self->login_button];
FBSDKAccessToken* access_token =[FBSDKAccessToken currentAccessToken];
NSLog(@"Access Token, %@",access_token);
}
来自 ApplicationDelegate.m
From ApplicationDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:[[RootViewController alloc] init]];
[self.window makeKeyAndVisible];
[self.window setBackgroundColor:[UIColor purpleColor]];
[FBSDKLoginButton class];
return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
}
我的 -ObjC 链接器标志也已设置
also my -ObjC linker flag is set
推荐答案
需要首先调用 FBSDKApplicationDelegate 来解析缓存的令牌.由于您立即设置根视图控制器,因此在 FBSDKApplicationDelegate 之前调用您的 viewDidLoad.相反,您可以将 FBSDKApplicationDelegate 向上移动:
The FBSDKApplicationDelegate needs to be called first to resolved cached tokens. Since you are setting the root view controller immediately, that calls your viewDidLoad before the FBSDKApplicationDelegate. Instead, you can move the FBSDKApplicationDelegate up:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[FBSDKLoginButton class];
BOOL r = [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:[[RootViewController alloc] init]];
[self.window makeKeyAndVisible];
[self.window setBackgroundColor:[UIColor purpleColor]];
return r;
}
这篇关于尽管通过 FBSDKLoginButton 登录,但 ios Facebook SDK v4.x 访问令牌为 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!