Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook loginViewFetchedUserInfo is called twice

I am using facebook SDK 3.0 in my app. The delegate method is called twice when after logging to facebook.

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user {
    //loginThroughFb=TRUE;
    NSString *userId=[[NSString alloc] initWithString:[user id]];
    [self soapCallForLogin:@"" password:@"" deviceId:@"" fbid:userId];
    NSLog(@"%@",userId);
    [userId release];

}
like image 645
Idrees Ashraf Avatar asked Oct 31 '12 11:10

Idrees Ashraf


Video Answer


1 Answers

I tried 'HelloFacebookSample' project and the method is called only once.

So I guess the best solution for such case is to keep a reference to the last user object and compare it to the new object you get the next call, and if they're equal you can just ignore that call.

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user {
    if (![self isUser:cachedUser equalToUser:user]) {
        cachedUser = user;
        /// Do something
    }
}

- (BOOL)isUser:(id<FBGraphUser>)firstUser equalToUser:(id<FBGraphUser>)secondUser {
    return
        [firstUser.objectID isEqual:secondUser.objectID] &&
        [firstUser.name isEqual:secondUser.name] &&
        [firstUser.first_name isEqual:secondUser.first_name] &&
        [firstUser.middle_name isEqual:secondUser.middle_name] &&
        [firstUser.last_name isEqual:secondUser.last_name] &&
        ...
}
like image 176
Hejazi Avatar answered Oct 04 '22 16:10

Hejazi