NSURLConnection IOS 3G issue

99封情书 提交于 2019-12-05 11:07:49

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.

try to use Reachability framework and check there if it returns false for 3G. If it does return true and you still get the timeout, try to go to sync model and see what happens. May be the connection works ok, but something intercepts your callback.

Is this https? I wonder if there may be some SSL validation failure going on... Also have you tried querying this from curl over 3G? If the cellular carrier proxies and isn't giving you valid data, or if its IP related (black list, closed port, etc), then you might get a different response. I'd test with curl to be sure. Either from a jail broken phone, or while tethered.

The problem with NSURLConnection over 3g is the timeout which is out of your hand basically ,,

If you are uploading or streaming a data to the server and that data handled there and needs sometime more than NSURLConnection time threshold or the connection is too slow the connection would be closed and returns NULL data .. that because the connection goes into IDLE state...

To overcome such issue you need to make the webservice sending an empty packets "spaces" You will see that the didReceiveData invoked on each packet arrival ..

The spaces wont affect the receivedData .. in my case the response is a JSON and I use JSonKit to parse it ,,...

hopefully it will help somebody ..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!