Questions tagged [nsurlsessionconfiguration]

An NSURLSessionConfiguration object defines the behavior and policies to use when uploading and downloading data using an NSURLSession object. When uploading or downloading data, creating a configuration object is always the first step you must take. You use this object to configure the timeout values, caching policies, connection requirements, and other types of information that you intend to use with your NSURLSession object.

An NSURLSessionConfiguration object defines the behavior and policies to use when uploading and downloading data using an NSURLSession object. When uploading or downloading data, creating a configuration object is always the first step you must take. You use this object to configure the timeout values, caching policies, connection requirements, and other types of information that you intend to use with your NSURLSession object.

It is important to configure your NSURLSessionConfiguration object appropriately before using it to initialize a session object. Session objects make a copy of the configuration settings you provide and use those settings to configure the session. Once configured, the session object ignores any changes you make to the NSURLSessionConfiguration object. If you need to modify your transfer policies, you must update the session configuration object and use it to create a new NSURLSession object.

NOTE In some cases, the policies defined in this configuration may be overridden by policies specified by an NSURLRequest object provided for a task. Any policy specified on the request object is respected unless the session’s policy is more restrictive. For example, if the session configuration specifies that cellular networking should not be allowed, the NSURLRequest object cannot request cellular networking.

For more information about using configuration objects to create sessions, see NSURLSession Class Reference.

141 questions
6
votes
2 answers

NSURLSessionConfiguration HTTPAdditionalHeaders not set

Authorization header is set in NSURLSessionConfiguration, however it is not attached to NSURLSessionDataTask. Is this a bug in Foundation framework? NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration…
5
votes
3 answers

Swift 4/5 setting adding proxy to WKWebview

I have looking for a way to set a proxy to WKWebview request with no luck. By another hand I have been able to set proxy to http request func createURLSessionConfiguration(_ host:String,_ port:String) -> URLSessionConfiguration { let config =…
5
votes
2 answers

How to set different expiration timeout for each NSURLRequest

Is it possible to set different expiration timeout for each request? The only way I found was to create a new NSURLSession with a different NSURLSessionConfiguration and change the timeoutIntervalForResource. Same thing with frameworks like…
Luca Torella
  • 7,974
  • 4
  • 38
  • 48
5
votes
1 answer

Downloading a list of 100 files one by one using NSURLSession in Background

I have implemented a download manager app targeting iOS 7+ using NSURLSession. The download manager has an enqueued list of files to be downloaded in priority order. The download works fine while the app is in background and delegate calls are…
4
votes
2 answers

Is it a proper way to use background task for additional HTTP request after background download/upload finishes?

I want to make an additional HTTP request after background download/upload in order to confirm that the application finished downloading/uploading. Let me show you a simple example. First we need to create download/upload task. let configuration =…
Nominalista
  • 4,632
  • 11
  • 43
  • 102
4
votes
1 answer

Changing allowsCellularAccess on existing NSURLSession

Is it possible to change the value for allowsCellularAccess on an existing NSURLSession by modifying the underlying NSURLSessionConfiguration? I want to honor any changes in a user's settings for my application without cancelling existing requests…
JustinHK
  • 758
  • 1
  • 6
  • 19
4
votes
1 answer

Swift 2 How do I implement proxy host and port that requires authorization?

This is the code I'm using to send a request using a proxy host and port. I know the implementation is correct because I'm getting a 407 status code (proxy authentication required). I don't know why the username/password to the proxy server aren't…
dbconfession
  • 1,147
  • 2
  • 23
  • 36
4
votes
2 answers

NSURLSessionConfiguration not accepting 'Content type' in HTTPAdditionalHeaders

I am making a REST web Service call using NSURLSession.I have set the content-Type for the webservice in NSURLSessionConfiguration.HTTPAdditionalHeaders. The below code was working absolutely fine in iOS 7.0 to iOS 8.1.3. But in iOS 8.3 the web…
CrazyDeveloper
  • 995
  • 1
  • 13
  • 24
4
votes
1 answer

iOS8 extension background NSURLSession sandbox error

I'm trying to upload a file from a sharing extension in the Photos app, using a background NSURLSession. Because a background NSURLSession only supports an upload task using the uploadTaskWithRequest:WithFile: API, I first get the URL for the image…
3
votes
0 answers

Implement URLProtocol but respect session configuration

I want to intercept all network calls (request and response) in an application, so I'm implementing a concrete URLProtocol subclass. Most online examples simply create a new URLSession with the default configuration for each task. Which means that…
3
votes
0 answers

SETTINGS_MAX_CONCURRENT_STREAMS in iOS when downloading over HTTP/2

In iOS, how to limit the maximum number of parallel download requests that are multiplexed over a single connection in HTTP/2. I am observing that 100's of requests are sent in parallel when downloading .ts files of a m3u8 video. There is a limit on…
Deep Arora
  • 1,900
  • 2
  • 24
  • 40
3
votes
1 answer

NSURLSession: can't get resume data after calling cancelByProducingResumeData

I want to resume downloading after user cancels downloading or something wrong happens. But when I call cancelByProducingResumeData method, the resumeData is nil. So, I can't resume downloading. I'm sure the download link can be resumed, because our…
3
votes
0 answers

Watch OS : NSUrlSession Credential caching

I want to implement "logout and new login" feature from iPhone and Apple Watch. I am able to clear the credentials from iPhone (Using NSURLConnection because its old code) after logout, but not able to from apple watch (Using NSURLSession). I am…
3
votes
1 answer

can NSURLProtocol work with NSURLSession {upload, download}dataTask

I have a custom NSURLProtocol #import @interface XXXURLProtocol : NSURLProtocol @property (nonatomic, strong) NSURLSession *session; @property (nonatomic, strong)…
3
votes
1 answer

ios NSURLSession (default configuration) does not cache requests

I've configured the session: - (void)createSession { NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; sessionConfig.requestCachePolicy = NSURLRequestReturnCacheDataElseLoad; _session…
1
2
3
9 10