Ios 使用NSURLCONNECTION和NSXMLPARSER的最佳实践是什么?

Ios 使用NSURLCONNECTION和NSXMLPARSER的最佳实践是什么?,ios,parsing,connection,Ios,Parsing,Connection,这个问题是关于在我的应用程序中实现连接和解析器的最佳方法 例如,我的应用程序包含15个URL请求,可以返回15个预期的XML格式响应 通常我遵循以下方法 1. URLManager //This file manages URL and request paths 2. MyConnection//In this Class, I make NSURLConnection and one delegate to return back to Controller when opertion i

这个问题是关于在我的应用程序中实现连接和解析器的最佳方法

例如,我的应用程序包含15个URL请求,可以返回15个预期的XML格式响应

通常我遵循以下方法

1. URLManager //This file manages URL and request paths

2. MyConnection//In this Class, I make NSURLConnection and one delegate to return back to Controller when opertion is done. I distinguish URLs using enum. 

3. Several Parsers for parsing NSData which my controller gets from Connection file. as parsing finished, I use Delegate to pass Parsed Data to Controller which is usually objects in an array to use in Controller.
通过这种方式,我需要制作许多解析器,并且在下载和解析值之前,还必须面对一段时间卡住的GUI

我想知道开发iOS应用程序的标准方法,以便它能够提供最佳的性能和稳定性

据我所说,谢谢

最好的方法是将sendAsynchronousRequest与块编码一起使用

webservice响应进程的枚举

用于xml到dict的转换

typedef void (^onGetSuccess)(BOOL success,NSArray *arrProduct);

**Webservice Calling**



 -(void)getData:(onGetSuccess)block{
    [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:GET_SERVERT_URL]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if ([data length]>0) {
            NSString *str=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSDictionary *dict=[NSDictionary dictionaryWithXMLString:str];
            NSMutableArray *arrRespoce=[dict objectForKey:@"dict"];
            block(YES,arrRespoce);
        }
        else{
            block(false,nil);
        }



    }];
}