ios Facebook SDK v4.x access token null despite being logged in via FBSDKLoginButton

前端 未结 6 575
花落未央
花落未央 2021-01-04 12:34

My facebook access token is null despite the fact that the button shows that I\'m logged in. Anyone know why this would be?

From RootViewController.m



        
6条回答
  •  無奈伤痛
    2021-01-04 13:11

    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;
    }
    

提交回复
热议问题