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
73
votes
1 answer

NSURLSession concurrent requests with Alamofire

I'm experiencing some strange behaviour with my test app. I've about 50 simultaneous GET requests that I send to the same server. The server is an embedded server on a small piece of hardware with very limited resources. In order to optimize the…
Hannes
  • 3,752
  • 2
  • 37
  • 47
29
votes
4 answers

Showing the file download progress with NSURLSessionDataTask

I want to display file download progress (how many bytes are received) of particular file. It works fine with the NSURLSessionDownloadTask .My question is I want to achieve the same with the NSURLSessionDataTask. Here is the code which receives file…
26
votes
3 answers

How to cache using NSURLSession and NSURLCache. Not working

I have a test app setup and it successfully downloads content from the network even if the user switches apps while a download is in progress. Great, now I have background downloads in place. Now I want to add caching. There is no point to me…
John Erck
  • 9,478
  • 8
  • 61
  • 71
24
votes
4 answers

Prevent NSURLSession from caching responses

Why does it cache responses. It returns previously fetched responses. It even works if turning off the network connection. Resetting the iOS simulator did not seem to work either. Making a request, then again with internet offline does work…
Sunkas
  • 9,542
  • 6
  • 62
  • 102
20
votes
5 answers

NSURLSessionTask never calls back after timeout when using background configuration

I am using NSURLSessionDownloadTask with background sessions to achieve all my REST requests. This way I can use the same code without have to think about my application being in background or in foreground. My back-end has been dead for a while,…
17
votes
2 answers

unable to upload file using NSURLSession multi-part form data in iOS

I am trying to upload a video / image file using- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL; method using multi-part form data. But somehow i am not able to upload the file and i am getting…
12
votes
6 answers

How to programmatically add a proxy to an NSURLSession

Looking over the documentation of NSURLSession and NSURLSessionConfiguration, I was under the impression I should configure it with a dictionary like the following: // Create a dictionary to describe the proxy NSDictionary *proxyDict = @{ …
Jeff
  • 6,646
  • 5
  • 27
  • 33
9
votes
2 answers

How to upload task in background using afnetworking

I'm trying to upload large files using AFNetworking and have the upload continue when the application is in the background. I can upload files just fine, but when I attempt to use a background configuration -- the application crashes with the…
8
votes
1 answer

How to set a 'Token xxxxxxxxxx' for 'Authorization' in HTTP header in URLSession

The backend APIs I'm working with require a token to be sent with every request against the HTTP header key Authorization in this format - Token xxxxxxxxxx. Right now, I'm doing the following. var getRequest = URLRequest(url:…
7
votes
1 answer

NSURLSession background transfer not working

I’m trying to download a series of files from server to iOS app, with the intent that the download of these files happen even when the App is in the background mode. I'm using background transfer provided by NSURLSession and its series of APIs. I…
7
votes
4 answers

NSURLSessionDownloadTask keeps retrying when using Background Configuration

I have a problem when it comes to a slow backend and downloading data with background configuration. NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:identifier]; _backgroundSession = [NSURLSession…
6
votes
1 answer

NSURLSession HTTPMaximumConnectionsPerHost not working as expected

I am trying to download .ts files of a .m3u8 Video. I have created a download task for each of the .ts url and the session configuration HTTPMaximumConnectionsPerHost property set to 4: NSURLSessionConfiguration *sessionConfig =…
6
votes
0 answers

URLSessionConfiguration's httpMaximumConnectionsPerHost not working in iOS 10?

Setting this parameter doesn't affect the number of simultaneous connections to a host. I've found the same issue on apple developer forum. It looks like a bug in iOS 10, iOS 9 works properly. let sessionConfiguration =…
6
votes
1 answer

NSURLSessionconfiguration.shouldUseExtendedBackgroundIdleMode : what does it do?

Could not find any documentation on this instance variable. Is it related at all to being able to handle the response to a network request even when the app has been moved to the background?
Protongun
  • 3,230
  • 1
  • 15
  • 13
6
votes
1 answer

What is the correct way to use backgroundCompletionHandler in Alamofire?

I'm not clear on how to use this properly but had seen other people doing this type of thing: func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) { …
Paul Young
  • 1,489
  • 1
  • 15
  • 34
1
2 3
9 10