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?
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
What about
- (void)fbDidNotLogin:(BOOL)cancelled
Does that get called?
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];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With