Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

iphone - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...