NSMutableURLRequest not obeying my timeoutInterval
There's a thread on Apple dev forums discussing this issue. Apparently on iPhone OS, the setter mandates timeoutInterval a minimum of 240 seconds (4 minutes). This only occurs when the postBody is not empty (typically when using a POST request). This seems crazy, but apparently it's there to make sure requests leave the system even though it might take many seconds for the WWAN (3G) interface to wake up. 240 seconds seems rather steep, so they suggest to set a timer and cancel the asynchronous connection when your timer fires. I know this seems stupid, but that's the only I managed to get timeout for POST requests... :-(
Asynchronous request timeout interval never stop
According to another question here on Stackoverflow, the default timeout for POST
is 240
seconds and any shorter intervals are ignored.
Link to answer here
Set the timeOut value for NSMutableURLRequest
According to this post the default timeout value (240) you mentioned is also the minimum value. You'll have to use another timer to cancel the request as described in the link.
Request Timeout NSURLSession
You can't modify your request because for some reason you went with immutable option. Since NSMutableURLRequest is a subclass of NSURLRequest you can use the very same initializer init(URL:cachePolicy:timeoutInterval:)
to create an mutable instance and set default timeout. And then configure (mutate) this request as you need.
let request = NSMutableURLRequest(URL: url!, cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 5.0)
NSURLConnection Taking Too long time
Use sendAsynchronousRequest
to avoid hanging your UI
and set the timeout Interval if you URL
taking too long time.
[NSMutableURLRequest setTimeoutInterval:10.0f];
Hope it cures....:)
Related Topics
How to Regenerate iOS Folder in React Native Project
Uitableview with Multiple Sections Using Realm and Swift
Wkwebview Open Links from Certain Domain in Safari
Load Local HTML into Uiwebview Using Swift
Open a View Controller When a iOS Push Notification Is Received
How to Detect Delete Key on an Uitextfield in iOS 8
Storing Images Locally on an iOS Device
How to Update a Coredata Entry That Has Already Been Saved in Swift
Gradient Polyline with Mapkit iOS
iOS Aes Encryption - Fail to Encrypt
Type 'Viewcontroller' Does Not Conform to Protocol 'Uitableviewdatasource'
Getting a Device Udid from .Mobileconfig
Does @Synchronized Guarantees for Thread Safety or Not
Entitlements File Do Not Match Those Specified in Your Provisioning Profile.(0Xe8008016)