Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 [XCode] NSURLRequest timeoutInterval not as set?

views
     
TSTamamama
post Nov 2 2015, 04:20 PM, updated 11y ago

On my way
****
Senior Member
507 posts

Joined: Sep 2010


hi guys, I'm trying to implement a retry on http request timeout on my IOS apps, i've set the timeout interval as the code below

CODE
NSMutableURLRequest *urlRequest = [client requestWithMethod:@"POST" path:@"something.php" parameters:(NSDictionary *)parameters ];
   
[urlRequest setTimeoutInterval:10];


the problem is, i tested the interval by connecting my iPhone to a 3g hotspot, then turning off the 3g and initiate the curl request and here's the result that i logged

QUOTE
2015-11-02 15:47:25.368 sportsbetting[876:218887] failure to connect, connection count: 0 error:
2015-11-02 15:47:29.417 [876:218887] failure to connect, connection count: 1 error:
2015-11-02 15:47:33.466 [876:218887] failure to connect, connection count: 2 error:
2015-11-02 15:47:37.519 [876:218887] failure to connect, connection count: 3 error:
2015-11-02 15:47:41.568 [876:218887] failure to connect, connection count: 4 error:


as you can see from the log time, the interval between retries is 4-5 secs apart and not 10 secs.. although this is acceptable for me, i'd like to know, why and where is the 4-5 sec limit set, i've googled around and couldn't find an answer to this. is it default to the NSURLRequest class? do apple enforce 4-5 sec retries on no internet? why is it like that? help guys, any answer is appreciated.

This post has been edited by Tamamama: Nov 3 2015, 02:07 AM
bandit9956
post Nov 11 2015, 12:51 PM

Getting Started
**
Junior Member
65 posts

Joined: Nov 2008
Hi,

If it were for me, I won't use the native URL request in Objective C

Try looking for AFNetworking.

Almost ALL iOS apps runs on it. It handles your timeout session in a block, and it is asynchronous, hence, you can control the timeout block as you like. smile.gif

Furthermore, if you were to check for slow / no internet, you should not use timeout as a threshold to determine whether 3g/4g/Wifi is available. It is not recommended.

Edit :

You can refer to this.
http://stackoverflow.com/questions/8304560...th-afnetworking

It maybe due to your POST request, and it was only fixed iOS 6 and above.

Try setting the timeout period higher, maybe to 60~120 seconds, see will it run correctly or not.

This post has been edited by bandit9956: Nov 11 2015, 12:57 PM

 

Change to:
| Lo-Fi Version
0.0174sec    0.33    5 queries    GZIP Disabled
Time is now: 15th December 2025 - 07:38 PM