1

I just upgraded my objective-C code to the newest Facebook SDK 4.0.1 and I can't really understand what am I missing in my login sequence. I followed exactly the guide and the login does work for me but my only problem is that I'm not sure how can I react to the login.

So what I'm trying to do is that as soon as the Facebook login succeeded I would like to fetch his details, now for some reason I can't find out how to do it.

I read that I should put the following code in my viewDidLoad:

if ([FBSDKAccessToken currentAccessToken]) {
    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
         if (!error) {
             NSLog(@"fetched user:%@", result);
         }
     }];
}

But this code is never being executed when the Facebook login finishes successfully.

When I used to work with the FBLoginView I used the below code in order to get the user details:

- (void)loginViewFetchedUserInfo:(FBSDKLoginManager *)loginView
                        user:(FBSDKProfile*)user {
NSLog(@"User Details");}

Is there any equivalent function that I can use with the new SDK ?

Thanks for helping !


Edit :

I rezlied I can use the function :

    - (void)  loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
                error:(NSError *)error{
    NSLog(@"LOGGED IN TO FACEBOOK");

}

But I think I should also add a delegate to my controller and I'm not sure how.. any help on this one? Am I in the right direction?

Thanks again !

2 Answers2

3

Make a custom method and get result into that

-(void)fetchUserInfo {
    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
         if (!error) {
             NSLog(@"fetched user:%@", result);
         }
     }];
}

You can call that function if login is successful.

- (void)  loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
                error:(NSError *)error{
    NSLog(@"LOGGED IN TO FACEBOOK");
    [self fetchUserInfo];
}

and in you viewDidLoad method

 - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib

    if ([FBSDKAccessToken currentAccessToken]) {
        NSLog(@"Token is available");
        [self fetchUserInfo];
    } else {
    FBSDKLoginButton *loginView = [[FBSDKLoginButton alloc] init];
    loginView.readPermissions =  @[@"email"];
    loginView.frame = CGRectMake(100, 150, 100, 40);
    loginView.delegate = self;
    [self.view addSubview:loginView];
    }
}
Dheeraj Singh
  • 5,143
  • 25
  • 33
  • Thanks, that is kind of what I already have and my main problem is that the function didCompleteWithResult is not being called after the user logged in successfully. – Oriel Belzer Apr 22 '15 at 15:01
  • Have you assigned delegate to LoginButton and if yes just try resetting simulator and try installing application once again. – Dheeraj Singh Apr 23 '15 at 04:28
  • Yes I did - the issue was with the Bolt framework that comes with the Facebook SDK, see my answer. – Oriel Belzer Apr 23 '15 at 16:53
0

At the end the solution was in here: Facebook iOS8 SDK build module error for FBSDKCoreKit

Thanks everyone for your help !

Community
  • 1
  • 1