Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fbDidLogin not called - iOS

I'm trying to implement facebook to my iOS app for a school project however I ran into a bit of a snag, namely the fbDidLogin method is not called.

I have created a sample object called FBFetcher as so:

    @interface FBFetcher : NSObject <FBDialogDelegate,FBSessionDelegate,FBRequestDelegate> {
    Facebook *facebook;
    FBFetcher *facebookFetcher; 
}
-(void)login; 
@property (retain) Facebook  *facebook;
@property (retain) FBFetcher *facebookFetcher; 
@end

In the FBFetcher.m:

    @implementation FBFetcher 
@synthesize facebookFetcher,facebook;


-(void)login{
    facebook = [[Facebook alloc] initWithAppId:@"...."]; 
    NSArray *permissions =  [[NSArray arrayWithObjects: @"offline_access",@"user_about_me", nil] retain];
    [facebook authorize:permissions delegate:self];

}

-(void)fbDidLogin {
    NSLog(@"Erfolgreich eingeloggt....");
}

@end

In my app delegate:

    -  (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 

    return [[[controller facebookFetcher] facebook] handleOpenURL:url];
}

I have a separate view controller with n action tied to a UIButton:

facebookFetcher = [[FBFetcher alloc] init];
[facebookFetcher login]; 

I can access the login and authorization page, however the method fbDidLogin never gets called. Any suggestions?

like image 238
John Stevens Avatar asked Apr 25 '11 22:04

John Stevens


3 Answers

The method never gets called because when you authorize, you are doing it in Safari. To take care of this, which I think is a bug from Facebook SDK by the way, open the facebook.m file and find the following line:

[self authorizeWithFBAppAuth:YES safariAuth:YES];

and change it to

[self authorizeWithFBAppAuth:NO safariAuth:NO];

This way you will never be sent to Safari, but everything will be done in a dialog.

Just test it and you'll see that the fbDidLogin method will get called.

Hope it will help

like image 103
Metodij Zdravkin Avatar answered Sep 23 '22 05:09

Metodij Zdravkin


What about

- (void)fbDidNotLogin:(BOOL)cancelled

Does that get called?

like image 21
Peter Avatar answered Sep 22 '22 05:09

Peter


Look for this function in Facebook.m. This is where Facebook calls your fbDidLogin function. First make sure this is being called, then debug into it. Make sure you've spelled/defined fbDidLogin correctly in your session delegate (no parameters). If not the respondsToSelector will fail and never call your delegate's function.

- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate
{
  self.accessToken = token;
  self.expirationDate = expirationDate;
  if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogin)])
  {
    [_sessionDelegate fbDidLogin];
  }
}
like image 1
rainhut Avatar answered Sep 19 '22 05:09

rainhut