Facebook iOs sdk iphone:从多个视图控制器调用 [英] Facebook iOs sdk iphone : Call from multiple viewcontroller

查看:129
本文介绍了Facebook iOs sdk iphone:从多个视图控制器调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照我的iPhone应用程序
从Facebook开始文档官方指南执行SSO,但是所有的都在同一个持有Facebook类的视图控制器中。
现在考虑我想登录一个导航控制器的第一个viewcontroller,然后从同一个导航控制器的第三个视图控制器调用图形api。
我认为我可以将变量从一个控制器共享到另一个控制器,但我想知道是否有一些经典的方法来完成这一点。事实上,我希望在以下类似的事情中完成以下任务:
在应用程序开始时,我希望登录,然后在我的应用程序中调用图形API(或fql)。

i followed the official guide from facebook dev doc for implementing SSO from my iphone app, but all is in the same viewcontroller who hold istance of "Facebook" class. Now consider i want to login in first viewcontroller of one navigationcontroller and then call graph api from the third viewcontroller of the same navigationcontroller. I think i can share the variable from one controller to another, but i wish to know if there is some "classic" ways to accomplish this. Indeed what i wish to accomplish in something like: At the start of app i wish to login and then call graph api (or fql) wherever i need in my app.

Thx

推荐答案

我刚刚这样做:

在YourApp_AppDelegate.h中

in the YourApp_AppDelegate.h

#import "FBConnect.h"

Facebook *facebook;

@property (nonatomic, retain) Facebook *facebook;

在YourApp_AppDelegate.m中

In the YourApp_AppDelegate.m

@synthesize facebook;

然后在你的应用程序didFinishLaunchingWithOptions:function:

Then in your application didFinishLaunchingWithOptions: function:

facebook = [[Facebook alloc] initWithAppId:@"YOUR_FACEBOOK_API"];

从您的viewController.h(任何一个),

From your viewController.h (any of them),

#import "YourApp_AppDelegate.h"

YourApp_AppDelegate *appDelegate;

然后,在您的viewController.m viewDidLoad函数中:

And then, in your viewController.m viewDidLoad function:

appDelegate = (YourApp_AppDelegate *)[[UIApplication sharedApplication] delegate];

现在,任何时候您想要参考您的Facebook单身,只需参考:

Now, anytime you want to refer to your Facebook singleton, just refer to it like:

[appDelegate.facebook authorize:nil delegate:self];

这篇关于Facebook iOs sdk iphone:从多个视图控制器调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆