FBRequestDelegate 仅适用于 AppDelegate?
我想将所有 Facebook 交互封装在 FacebookFacade
类中,以保持干净整洁。我的 FacebookFacade
中有一个 iOS SDK Facebook 类的实例。
我的问题是,当我在外观内进行图形 API 调用时,例如:
[self.facebook requestWithGraphPath:@"me" andDelegate:self];
被调用的 FBRequestDelegate 的唯一方法是 requestLoading: ,没有其他方法。我尝试将类似的代码放在其他地方,例如在控制器和其他模型中,并且也没有调用所有 FBRequestDelegate
方法,仅调用 requestLoading:
。
事实上,我调用其他 FBRequestDelegate
方法的唯一方法是将所有 Facebook 逻辑放入 AppDelegate
中,并创建我的 AppDelegate
FBRequestDelegate。
为什么会这样呢?我在这里错过了什么吗?我绝对不想使用 AppDelegate
作为我的 FBRequestDelegate
,因为我不想混淆 AppDelegate
的用途。
谢谢。
I want to encapsulate all my Facebook interactions within a FacebookFacade
class to keep things clean and tidy. I have an instance of the iOS SDK Facebook class within my FacebookFacade
.
My problem is that when I make a Graph API call within the facade, such as:
[self.facebook requestWithGraphPath:@"me" andDelegate:self];
The only method of FBRequestDelegate
that gets called is requestLoading:
and nothing else. I have tried putting similar code in other places, like in controllers and other models, and there too not all of the FBRequestDelegate
methods get called, only requestLoading:
.
In fact the only way I can get the other FBRequestDelegate
methods to be called is to put all my Facebook logic in the AppDelegate
and make my AppDelegate
the FBRequestDelegate
.
Why is this the case? Am I missing something here? I definitely do not want to use the AppDelegate
as my FBRequestDelegate
as I don't want to confuse the purpose of the AppDelegate
.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
今天下午也遇到同样的问题。最后解决了:
您必须从主线程发出 FBRequest。
否则底层 NSURLConnect (在 facebook 对象中)永远不会启动。
Had the same problem this afternoon. Finally solved it:
You HAVE TO make your FBRequest from the MAIN thread.
Otherwise underlying NSURLConnect (in facebook object) never starts.
您可以与应用程序中的其他控制器共享您的 appDelegate。
我通过将我的 AppDelgate (实例化并分配其中的 facebook 对象)导入到我的界面中解决了这个问题,即
这样,我可以创建一个指向委托对象的指针,并在我需要的地方使用 facebook 方法。
如果这不起作用请告诉我
You can share your appDelegate with the other controllers in your application.
I solved this problem by importing my AppDelgate (which instantiates and allocates the facebook object in it) into my interface, i.e
This way, i can create a pointer to point to the delegate object and use the facebook methods in where i need to.
Let me know if this doesn't work
确保当 facebook 在后台工作时,初始对象不会被释放。如果是,当 facebook 去调用委托并发现它为零或捕获错误时,它不会回调。
Make sure that the initial object is not being released while facebook is working in the background. If it is, when facebook goes to call the delegate and finds it nil or catches an error, it will not call back.