我想等到服务器响应并解析 XML 完成,然后调用另一个函数。我怎样才能做到这一点?我使用此代码向服务器发送请求并使用 NSXMLParser 解析 XML 响应。
NSURL *url1 = [NSURL URLWithString:@"linkserver"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL: url1] ;
NSDictionary *params1 = @{
@"a" : vd;
@"b" : @"all"
};
NSMutableURLRequest *afRequest = [httpClient requestWithMethod:@"GET" path:nil parameters:params1] ;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
NSString * parsexmlinput = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
[self parseXMLFile:parsexmlinput];// parse xml
[self getItemFromStatus];// wait to call another function at here???
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", error);
}
];
[httpClient enqueueHTTPRequestOperation:operation];
}
请给我任何建议。非常感谢