我正在努力寻找在cocos 2d中实现Facebook api的方法,但我找不到一个。
有人可以帮助我吗?
答案 0 :(得分:0)
执行此操作的最佳方法是使用类似“共享实例”函数的单例模型对象。
这样,当应用程序开始运营并且您不主动需要FB时,您可以将会话保留在一边并按如下方式调用它。
//create a static void
static FacebookModel *sharedInstance = nil;
//In the model
+(FacebookModel *) sharedInstance {
if (sharedInstance == nil) {
<INSTANTIATE FACEBOOK with an FB property>
<LOG INTO FACEBOOK with that property>
}
return sharedInstance;
}
-(void)selectorWhichPostsToFacebook {
<USE CODE HERE TO POST TO FB>
>
//In your view did load for any class that needs it...
FacebookModel *fM = [FacebookModel sharedInstance];
//then when you need to actually use fb to do something...
[fM selectorWhichPostsToFB];