Facebook SDK v4.0 for iOS - FBSDKProfile currentProfile not being set

前端 未结 8 2617
星月不相逢
星月不相逢 2020-12-25 13:35

I\'ve just \"upgraded\" my Facebook SDK to 4.0 for my iOS app.

I\'ve got the log in working okay, however, according to the documentation, I\'m now supposed to use

8条回答
  •  悲&欢浪女
    2020-12-25 14:22

    I'm in objc but ran into this problem as well.

    First, Johnny Z's answer is correct that you have to explicitly enable the FBSDKProfile class by setting 'enableUpdatesOnAccessTokenChange' to true and then observing changes. In fact, that's what FBSDKProfile is doing internally according to the header comments.

    However, as noted by fanfan in a comment, the FBSDKProfile doesn't have all of the fields you might be interested in. I ended up not using FBSDKProfile and just made a graph request for 'me' like so:

        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
             startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                 if (error) {
                     CLS_LOG(@"Login error: %@", [error localizedDescription]);
                     return;
                 }
    
                 NSLog(@"fecthed user: %@", result);
    }];
    

    Note: You can still observe changes with the 'FBSDKProfileDidChangeNotification' notification. Read FBSDKAccessToken.h comments for documentation of this notification and the keys it will send.

提交回复
热议问题