本文介绍了未调用 fbDidLogin - iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 facebook 实施到我的 iOS 应用程序以用于学校项目,但是我遇到了一些障碍,即未调用 fbDidLogin 方法.

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.

我创建了一个名为 FBFetcher 的示例对象,如下所示:

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

在 FBFetcher.m 中:

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

在我的应用委托中:

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

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

我有一个单独的视图控制器,其中 n 个动作与 UIButton 绑定:

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

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

我可以访问登录和授权页面,但是从未调用过 fbDidLogin 方法.有什么建议?

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

推荐答案

该方法永远不会被调用,因为当您授权时,您是在 Safari 中进行的.为了解决这个问题,顺便说一下,我认为这是 Facebook SDK 的一个错误,打开 facebook.m 文件并找到以下行:

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];

并将其更改为

[self authorizeWithFBAppAuth:NO safariAuth:NO];

这样您将永远不会被发送到 Safari,但一切都将在对话框中完成.

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

只要测试一下,您就会看到 fbDidLogin 方法将被调用.

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

希望能帮到你

这篇关于未调用 fbDidLogin - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 12:33