我正在使用AFXMLRequestOperation
奇妙的方法AFNetworking
。我想使用的是使用以下内容,但使用我自己的完成回调将我自己的方法包裹起来。
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];
是否可以执行以下操作?
+ (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?
}
}
然后使用以下命令调用它:
[MyClass makeRequestWithURL:url completion^(BOOL finished){
if (finished) {
NSLog(@"AFNetworking Finished");
}
}];
我可以知道AFNetworking
我的完成块何时完成吗?