Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLConnection IOS 3G issue

I have used NSURLConnection (asynchronous) in my app which is working fine on wifi (iOS5 & iOS6). But its creating an issue with 3G. When I run my app 3G connection then I dont get any data in my didReceiveData method.

I have putted logs in my delegate methods, but while using 3G, The request is getting timed out. What can be the issue.

EDIT: On server side -> It shows that my request has been sent to server & server has also sent the response to the client.

EDIT 2:

The code which I have written is as follows.

NSURL *url = [NSURL URLWithString:@"someURL"];

NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url     
 cachePolicy:NSURLRequestUseProtocolCachePolicy                                   
 timeoutInterval:40.0];

//[req setHTTPShouldUsePipelining:YES];

[req setValue:@"x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[req setValue:@"someValue" forHTTPHeaderField:@"Accept"];
[req setValue:@"myCrdentails" forHTTPHeaderField:@"Authorization"];
[req setHTTPMethod:@"GET"];

[[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];

The response headers are as below

< HTTP/1.1 200 OK
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Content-Type: text/event-stream; charset=utf-8
< Connection: keep-alive
< Transfer-Encoding: chunked
like image 939
JiteshW Avatar asked Nov 12 '22 19:11

JiteshW


1 Answers

After struggling with this issue for hours I finally found a working solution. The NSMutableURLRequest object has a method to set whether cellular networks are allowed or not:

[req setAllowsCellularAccess:YES];

Even though the value seems to be YES by default for objects of type NSURLRequest, it solved the problem for me.

Hopefully this will help someone like me struggling with the issue and ending up on this question.

like image 104
ThomasKJDK Avatar answered Nov 15 '22 08:11

ThomasKJDK