# Modules.URLSession.Session
The session object used to start new tasks.
# Overview
These APIs are supported on iOS 7 and later.
The NSURLSession class and related classes provide an API for downloading content. This API provides a rich set of delegate methods for supporting authentication and gives your app the ability to perform background downloads when your app is not running or, in iOS, while your app is suspended.
iOS Background Services guide (opens new window).
# Properties
# configuration CREATION ONLY
The configuration used for this url session.
Configuration options for an Modules.URLSession.Session object.
When a session is created, a copy of the configuration object is made.
you cannot modify the configuration of a session after it has been created.
The shared session uses the global singleton credential, cache and cookie storage objects.
An ephemeral session has no persistent disk storage for cookies, cache or credentials.
A background session can be used to perform networking operations on behalf of a suspended application, within certain constraints.
# Methods
# dataTask
Creates a data task for the specified URL, within the provided session object and local data.
An data task does not provide any additional functionality over a usual session task and its presence is merely to provide lexical differentiation from download and upload tasks.
Once this function is called, the task starts automatically. Once finished,
the data task will call the sessioncompleted
event containing infos about
the response.
Parameters
Name | Type | Description |
---|---|---|
args | UploadDataTaskType | An object representing the arguments to add a new task task. |
Returns
Task's identifier number.
- Type
- String
# downloadTask
Creates a download task for the specified URL, within the provided session object and saves the results to a file.
Once this function is called, the download starts automatically. The progress
of the download can be monitored by listening to the downloadprogress
,
downloadcompleted
, sessioneventscompleted
and sessioncompleted
events.
Parameters
Name | Type | Description |
---|---|---|
args | DownloadTaskType | An object representing the arguments to add a new background task. |
Returns
Task's identifier number.
- Type
- String
# finishTasksAndInvalidate
Invalidates the given session object, allowing any outstanding tasks to finish.
This method returns immediately without waiting for tasks to finish. Once a session is invalidated,
new tasks cannot be created in the session, but existing tasks continue until completion. Once
invalidated, references to the events and callback objects are broken. Session objects cannot be
reused. To cancel all outstanding tasks, call invalidateAndCancel
instead.
Returns
- Type
- void
# flush
Flushes storage to disk and clear transient network caches.
Parameters
Name | Type | Description |
---|---|---|
callback | Callback<CompletedCallback> | Callback to be invoked when the reset completes. |
Returns
- Type
- void
# invalidateAndCancel
Cancels all outstanding tasks and then invalidates the session object.
Once invalidated, references to the events and callback objects are broken.
Session objects cannot be reused. To allow outstanding tasks to run until
completion, call finishTasksAndInvalidate
instead.
Returns
- Type
- void
# reset
Empties all cookies, cache and credential stores, removes disk files, calls flush.
Parameters
Name | Type | Description |
---|---|---|
callback | Callback<CompletedCallback> | Callback to be invoked when the reset completes. |
Returns
- Type
- void
# uploadTask
Creates a upload task for the specified URL, within the provided session object and local data.
Once this function is called, the upload starts automatically. The progress
of the upload can be monitored by listening to the uploadprogress
and
sessioncompleted
events.
Parameters
Name | Type | Description |
---|---|---|
args | UploadDataTaskType | An object representing the arguments to add a new upload task. |
Returns
Task's identifier number.
- Type
- String