Facebook API - 如何取消图表请求 [英] Facebook API - How to cancel Graph Request

查看:125
本文介绍了Facebook API - 如何取消图表请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶尔需要取消FaceBook图表请求,但在API中似乎没有取消或类似的方法。目前,我分配给请求的代表已经被取消分配,有时会发生崩溃。有没有办法取消一次提交的图表请求?

I occasionally need to cancel a FaceBook graph request, but there seems to be no cancel or similar method in their API to do so. At the moment, crashes sometimes occur as the delegate I assigned to the request has been deallocated. Is there any way to cancel a graph request once submitted please?

推荐答案

我假设你在说Facebook- ios-sdk项目,以及在Facebook.h中缺少取消方法。我也注意到这一点,最终决定添加我自己的取消方法。只是要注意,您分配给请求的代理不应该被dealloc'd然后被引用,因为请求保留代表。请参阅此类似问题 。现在,如果你发现自己真的需要一个取消方法的其他原因...

I'm assuming you're talking about the facebook-ios-sdk project, and the lack of a cancel method in Facebook.h. I noticed this as well, and eventually decided to add my own cancel method. Just to note, the delegate you assign to the request shouldn't ever be dealloc'd and then referenced, because the request retains the delegate. See this similar question. Now, if you find yourself really needing a cancel method for some other reason...

添加取消方法:

Facebook的请求是以不透明的方式进行的。你永远不会看到他们,只能通过 Facebook 类来听取结果。在引擎盖下, Facebook 类使Graph API请求与(不公开使用) FBRequest 类。这个类基本上是一个花哨的 NSURLConnection 委托。所以要取消请求,成员 NSURLConnection 只需要被告知 cancel 。将此方法添加到FBRequest中:

Adding a cancel method:
Facebook requests are made in an opaque manner. You never see them, and only hear about results via the Facebook class. Under the hood, the Facebook class makes Graph API requests with the (not for public use) FBRequest class. This class is is basically a fancy NSURLConnection delegate. So to cancel the request, the member NSURLConnection just has to be told to cancel. Adding this method to FBRequest:

// Add to FBRequest.h
- (void)cancel;

And ...

// Add to FBRequest.m
- (void)cancel {
    [_connection cancel];
    [_connection release], _connection = nil;
}

现在,在Facebook类中公开一个界面,以利用新的方法...

Now, to expose an interface in the Facebook class to make use of the new method...

// Add to Facebook.h
- (void)cancelPendingRequest;  

And ...

// Add to Facebook.m
- (void)cancelPendingRequest {
    [_request cancel];
    [_request release], _request = nil;
}

这就是它的一切。上述方法将取消最近的请求,您将永远不会再收到。

That's all there is to it. The method above will cancel the most recent request, and you'll never hear from it again.

这篇关于Facebook API - 如何取消图表请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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