I am using an NSURLConnection
in my app where I scan a barcode, send the XML via the NSURLConnection
and the java service sends me back an XML.
My problem here is that with Wifi, the response time is decent, but when I use 3G, it's freaking slow.
How can I manage to fasten things up in 3G?
NSString *xmlHomeMade = [NSString stringWithFormat:
@"<?xml version='1.0'?>"
"<service name='CorePDAService' method='blahblah'>"
"<arg class='java.lang.String'>%@</arg>"
"</service>",cab];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *ipAgence = [defaults objectForKey:@"ipAgence"];
NSLog(@"agence IP Test : %@",ipAgence);
NSURL *url = [NSURL URLWithString:ipAgence];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [xmlHomeMade length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:10];
[theRequest setHTTPBody: [xmlHomeMade dataUsingEncoding:NSUTF8StringEncoding]];
NSError *error = nil;
NSURLResponse *urlResponse = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error] ;
if(urlResponse == nil){
if (error) {
[self displayAlert:@"" message:@"Error"];
}
}
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
[self parseXML:data];