本文介绍了Facebook类的Facebook Facebook SDK是否具有取消方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法取消Facebook对象的待处理请求?



我在Facebook.h中找不到任何方法,或者访问底层的 NSURLConnection 对象的方法。如果我按在导航栏上,并且它们是一个待处理的异步Facebook请求,则一旦响应到来,该请求会尝试将消息发送到解除分配的视图,导致

解决方案

对于遇到这个问题的人来说,似乎Matt的观察结果不适用于最新的facebook- iphone-SDK。参数不再明确保留在相关方法中:

  +(FBRequest *)getRequestWithParams:(NSMutableDictionary *)params 
httpMethod :( NSString *)httpMethod
委托:(id< FBRequestDelegate>)委托
requestURL:(NSString *)url {

FBRequest * request = [[FBRequest alloc] init] autorelease];
request.delegate = delegate;
request.url = url;
request.httpMethod = httpMethod;
request.params = params;
request.connection = nil;
request.responseText = nil;

所以代理的内存管理可以归结为.h文件中的属性声明:

  @property(nonatomic,assign)id< FBRequestDelegate>代表; 

这意味着现在可以发生崩溃,因为委托对象可以在FBRequest完成之前被释放。 / p>

更新:



在问题,以允许取消挂起的FBR请求。



更新2:



为避免在FBRequest完成之前代理被取消分配的情况下崩溃,您需要取消主动的FBRequest的连接,当你释放代理(这基本上是马特建议在链接的问题)。但是(我不知道这是否是新的),您可以直接对FBRequest执行此操作,因为它暴露了它的NSURLConnection属性。因此,如果您在属性中保留FBRequest对象:

  @property(nonatomic,retain)FBRequest * myRequest; 

并在您拨打电话时保存请求对象:

  self.myRequest = [facebookObj requestWithGraphPath:@meandDelegate:self]; 

您可以清理您的dealloc中的所有内容:

   - (void)dealloc 
{
if(myRequest){
[[myRequest connection] cancel];
[[myRequest release];
}

...

[super dealloc];
}

显然,你也应该在委托方法中释放和使用FBRequest属性一旦您处理了回复。


Is there anyway to cancel a Facebook object's pending request?

I can't find any methods in Facebook.h, or a way to access the underlying NSURLConnection object. If I press back on the navigation bar and the their is a pending asynchronous Facebook request, the request tries to send a message to a deallocated view once the response has come, causing the application to crash.

解决方案

For anyone who comes across this question, it appears that Matt's observation does not apply to the newest facebook-iphone-sdk. The parameters are no longer explicitly retained in the relevant method:

+ (FBRequest *)getRequestWithParams:(NSMutableDictionary *) params
                         httpMethod:(NSString *) httpMethod
                           delegate:(id<FBRequestDelegate>) delegate
                         requestURL:(NSString *) url {

  FBRequest* request = [[[FBRequest alloc] init] autorelease];
  request.delegate = delegate;
  request.url = url;
  request.httpMethod = httpMethod;
  request.params = params;
  request.connection = nil;
  request.responseText = nil;

So memory management for the delegate falls back to the property declaration in the .h file:

@property(nonatomic,assign) id<FBRequestDelegate> delegate;

This means a crash is now possible since the delegate object can be deallocated before the FBRequest is completed.

Update:

A possible workaround is suggested in this question to allow cancellation of pending FBRequests.

Update 2:

To avoid a crash in the case where the delegate gets deallocated before the FBRequest finishes, you need to cancel the active FBRequest's connection as you deallocate the delegate (which is basically what Matt suggests in the linked question). However (I'm not sure if this is new), you can do this directly to the FBRequest since it exposes it's NSURLConnection property. So, if you retain your FBRequest object in a property:

@property (nonatomic, retain) FBRequest *myRequest;

and save the request object when you make your call:

self.myRequest = [facebookObj requestWithGraphPath:@"me" andDelegate:self];

you can clean everything up in your dealloc:

- (void)dealloc
{
 if( myRequest ) {
    [[myRequest connection] cancel];
    [[myRequest release];
  }

  ...

  [super dealloc];
}

Obviously, you should probably also release and nil the FBRequest property in the delegate methods once you have processed the response.

这篇关于Facebook类的Facebook Facebook SDK是否具有取消方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 05:14