FBRequestDelegate 仅适用于 AppDelegate?

发布于 2024-10-09 16:05:40 字数 721 浏览 2 评论 0原文

我想将所有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兔小萌 2024-10-16 16:05:40

今天下午也遇到同样的问题。最后解决了:
您必须从主线程发出 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.

放肆 2024-10-16 16:05:40

您可以与应用程序中的其他控制器共享您的 appDelegate。

我通过将我的 AppDelgate (实例化并分配其中的 facebook 对象)导入到我的界面中解决了这个问题,即

#import "MyAppDelegate.h"

interface MyViewController: UIViewController <FBRequestDelegate, FBDialogDelegate, FBSessionDelegate>

这样,我可以创建一个指向委托对象的指针,并在我需要的地方使用 facebook 方法。

-(void) someFunction{
      MyAppDelgate *sharedAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]
      [sharedAppDelegate.facebook dialog:@"feed" andDelegate:self]; 
}

如果这不起作用请告诉我

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

#import "MyAppDelegate.h"

interface MyViewController: UIViewController <FBRequestDelegate, FBDialogDelegate, FBSessionDelegate>

This way, i can create a pointer to point to the delegate object and use the facebook methods in where i need to.

-(void) someFunction{
      MyAppDelgate *sharedAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]
      [sharedAppDelegate.facebook dialog:@"feed" andDelegate:self]; 
}

Let me know if this doesn't work

眼泪淡了忧伤 2024-10-16 16:05:40

确保当 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文