I am using the AFXMLRequestOperation method of the wonderful AFNetworking. What I would like to use is use the following, but wrap my own method around it, with my own completion callback.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.flickr.com/services/rest/?method=flickr.groups.browse&api_key=b6300e17ad3c506e706cb0072175d047&cat_id=34427469792%40N01&format=rest"]];
AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
XMLParser.delegate = self;
[XMLParser parse];
} failure:nil];
[operation start];
Is it possible to do something like the following?
+ (void)makeRequestWithURL:(NSURL *)url completion:(void (^)(BOOL finished))completion {
NSURLRequest *request = [NSURLRequest requestWithURL:url]];
AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
XMLParser.delegate = self;
[XMLParser parse];
} failure:nil];
[operation start];
if (completion) {
// How can I call my cometion block when AFXMLRequestOpersation is finished?
}
}
Then call it using:
[MyClass makeRequestWithURL:url completion^(BOOL finished){
if (finished) {
NSLog(@"AFNetworking Finished");
}
}];
Can can I know when AFNetworking has finished in MY completion block?
Just call your completion block in the success block:
You should also implement the failure block of
AFXMLRequestOperation.