Facebook iOS - handleOpenURL& Tabbar应用程序 [英] Facebook iOS - handleOpenURL & Tabbar Application
问题描述
我遇到困难让Facebook登录在我的应用程序中回到正确的视图,并调用相应的Facebook功能。
I'm having difficulties getting the Facebook Log In to kick back to the right view in my app and call the appropriate facebook functions.
在Facebook的这个例子中,Facebook只是简单的[控制器]。我正在使用Tabbar应用程序,因此我没有必要的参考。我指出了所需的视图,并使用它...正确打开,但不会调用任何与Facebook相关的方法,具体来说:
In the example Facebook has simply [controller facebook] that is the view they start with. I am using a tabbar application though so I don't have the necessary reference. I made a pointer to the desired view and used it... it opened correctly but would not call any of the methods associated with facebook, specifically:
(void)fbDidLogin;
(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[*NotReferencedViewController* facebook] handleOpenURL:url];
}
有没有人遇到这个?
推荐答案
不知道你在说什么,但是您应该将Facebook对象创建并存储在中心位置,例如Model或 UIApplicationDelegate
。然后,它将通过单例访问,以便您始终可以访问它,例如:
Not sure what example you're talking about, but you should create and store your Facebook object in a central place such as your Model or UIApplicationDelegate
. Then it would be accessible through singletons so you always have access to it, for example:
[[UIApplication sharedApplication] delegate].facebook
所以你可以从控制器需要的任何视图访问Facebook对象。
So you can then access the facebook object from whatever view controllers need it.
当您执行类似
NSArray* permissions = [[NSArray arrayWithObjects:@"email", @"read_stream", @"publish_stream", nil] retain];
[facebook authorize:permissions delegate:self];
指定委托:self
意味着您将实现Facebook可以通过这种方式通知您某些事件。其中一种方法是 fbDidLogin
,您可以在其中执行以下操作:
specifying delegate:self
means you will implement methods in that class that Facebook can call to inform you of certain events. One of those methods is fbDidLogin
, and in there you can do whatever you need to:
-(void)authorizeFacebook {
NSArray* permissions = [NSArray arrayWithObjects:@"email", @"read_stream", @"publish_stream", nil];
[facebook authorize:permissions delegate:self];
}
// if the authorization succeeds it will come back to your app and call the method below
-(void)fbDidLogin {
// switch view, call the facebook graph, or do whatever else you like
}
你可以这样做应用程序委托本身,或在视图控制器中。
You could do this in the app delegate itself, or in a view controller.
您可以通过检查facebook SDK的.h文件来查看Facebook代理方法:Facebook.h,FacebookRequest。 h等等
You can see the facebook delegate methods by inspecting the .h files of the facebook SDK: Facebook.h, FacebookRequest.h, etc.
修改
而您的 handleOpenURL:
方法应该与fb的示例(假设您不处理其他url方案)完全一样:
And your handleOpenURL:
method should look exactly as it does in fb's example (assuming you are not handling other url schemes):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
http://developers.facebook.com/docs/guides/mobile/#ios
这篇关于Facebook iOS - handleOpenURL& Tabbar应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!