问题描述
我试图在我的iOS应用程序中实现Facebook的一个学校项目,但是我遇到了一个陷阱,即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
在我的应用程序委托中: / p>
In my app delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[[controller facebookFetcher] facebook] handleOpenURL:url];
}
我有一个单独的视图控制器,n行为绑定到UIButton: p>
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!