我尝试将 AFNetworking 2.0 与 XML Web 服务调用集成,但我不知道我做错了什么。
首先,我通过扩展AFHTTPRequestOperationManager创建了一个共享客户端:
+ (instancetype)sharedClient {
static AFAppDotNetAPIClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[AFAppDotNetAPIClient alloc] initWithBaseURL:[NSURL URLWithString:AFAppDotNetAPIBaseURLString]];
_sharedClient.responseSerializer = [AFXMLParserResponseSerializer new];
});
return _sharedClient;
}
然后,我尝试使用 NSXMLParseDelegate 协议解析结果,但我无法获取任何数据。链接有效。
+ (AFHTTPRequestOperation *)globalTimelinePostsWithBlock {
return [[AFAppDotNetAPIClient sharedClient] GET:@"http://www.enetpulse.com/wp-content/uploads/sample_xml_feed_enetpulse_soccer.xml" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSXMLParser* parser = [[NSXMLParser alloc]initWithData:operation.responseData];
[parser setDelegate:(id<NSXMLParserDelegate>)self];
BOOL result = [responseObject parse];
} failure:nil];}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict {
NSLog(@"found");
} ...
有谁知道我做错了什么?