Question

This question is regarding the best way to implement connections and parsers in my app.

For Instance, my application contains 15 URL request which can return 15 expected return XML format responses.

Usually I Follow the following method.

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.

By this way I need to make many parsers and also had to face stuck GUI for a whiile until values gets downloaded and parsed.

I want to know the standard way to develop an iOS application so that it could give best performance and stability.

Thanks

Was it helpful?

Solution

According to me.

The Best way is to use sendAsynchronousRequest with block coding

enum for the webservice respoce.

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);
        }



    }];
}

For the xml to dict convertion

XMLDictionary

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top