so i’m using AFNetworking for doing asynchronous requests with web-services.
AFJSONRequestOperation *operation = [AFJSONRequestOperation operationWithRequest:request success:^(id JSON)
{
[self doSomeStuff];
} failure:^(NSHTTPURLResponse *response, NSError *error)
{
XLog("%@", error);
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
now what happens when the “self” object is dealloced before the request finished is, that my application chrashes on [self doSomeStuff]; of course.
is there a way to cancel this block-request when deallocating my object?
I did some sample code and the result can interest to you.
I created a class that creates a request just like yours:
And called this with:
The result that I got was:
Your object should be retained when passed inside the block. It should be avoiding these crashes.
Either way, as Micheal answered, it should be possible to call
cancelas long as you have access to the operation object.