Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSURLSessionMBS class.

NSURLSessionMBS.dataTaskDidBecomeDownloadTask(dataTask as NSURLSessionDataTaskMBS, downloadTask as NSURLSessionDownloadTaskMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The data task was changed to a download task.

dataTask: The data task that was replaced by a download task.
downloadTask: The new download task that replaced the data task.

When your dataTaskDidReceiveResponse event uses the ResponseBecomeDownload disposition to convert the request to use a download, the session calls this event to provide you with the new download task. After this call, the session receives no further event calls related to the original data task.

Some examples using this event:

NSURLSessionMBS.dataTaskDidBecomeStreamTask(dataTask as NSURLSessionDataTaskMBS, downloadTask as NSURLSessionStreamTaskMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The data task was changed to a stream task.

dataTask: The data task that was replaced by a stream task.
streamTask: The new stream task that replaced the data task.

When your dataTaskDidReceiveResponse event uses the ResponseBecomeStream disposition to convert the request to use a stream, the session calls this event to provide you with the new stream task. After this call, the session receives no further event calls related to the original data task.

For requests that were pipelined, the stream task allows only reading, and the object immediately sends the delegate message writeClosedForStreamTask. You can disable pipelining for all requests in a session by setting the HTTPShouldUsePipelining property on its NSURLSessionConfigurationMBS object, or for individual requests by setting the HTTPShouldUsePipelining property on an NSURLRequestMBS object.

Some examples using this event:

NSURLSessionMBS.dataTaskDidReceiveData(dataTask as NSURLSessionDataTaskMBS, data as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The data task has received some of the expected data.

dataTask: The data task that provided data.
data: A data object containing the transferred data.

This event may be called more than once, and each call provides only data received since the previous call. The app is responsible for accumulating this data if needed.

Some examples using this event:

NSURLSessionMBS.dataTaskDidReceiveResponse(dataTask as NSURLSessionDataTaskMBS, response as NSURLResponseMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The data task received the initial reply (headers) from the server.

dataTask:

The data task that received an initial reply.
response: A URL response object populated with headers.

Return your decision whether to continue a transfer, passing a NSURLSessionResponseDisposition constant to indicate whether the transfer should continue as a data task or should become a download task.

  • If you pass ResponseAllow, the task continues as a data task.
  • If you pass ResponseCancel, the task is canceled.
  • If you pass ResponseBecomeDownload, your delegate’s dataTaskDidBecomeDownloadTask method is called to provide the new download task that supersedes the current task.

Implementing this method is optional unless you need to cancel the transfer or convert it to a download task when the response headers are first received. If you don’t provide this event, the session always allows the task to continue.
You also implement this method if you need to support the fairly obscure multipart/x-mixed-replace content type. With that content type, the server sends a series of parts, each of which is intended to replace the previous part. The session calls this method at the beginning of each part, followed by one or more calls to dataTaskDidReceiveData with the contents of that part.

Each time the dataTaskDidReceiveResponse method is called for a part, collect the data received for the previous part (if any) and process the data as needed for your application. This processing can include storing the data to the filesystem, parsing it into custom types, or displaying it to the user. Next, begin receiving the next part by calling the completion handler with the NSURLSessionResponseAllow constant. Finally, if you have also implemented taskDidCompleteWithError, the session will call it after sending all the data for the last part.

Some examples using this event:

NSURLSessionMBS.dataTaskWillCacheResponse(dataTask as NSURLSessionDataTaskMBS, proposedResponse as NSCachedURLResponseMBS) as NSCachedURLResponseMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
Asks the event whether the data (or upload) task should store the response in the cache.

dataTask: The data (or upload) task.
proposedResponse: The default caching behavior. This behavior is determined based on the current caching policy and the values of certain received headers, such as the Pragma and Cache-Control headers.

Please return the new respnose:

Provide either the original proposed response, a modified version of that response, or nil to prevent caching the response.

The session calls this event after the task finishes receiving all of the expected data. If you don’t implement this method, the default behavior is to use the caching policy specified in the session’s configuration object. The primary purpose of this method is to prevent caching of specific URLs or to modify the userInfo dictionary associated with the URL response.

This method is called only if the NSURLProtocol handling the request decides to cache the response. As a rule, responses are cached only when all of the following are true:

  • The request is for an HTTP or HTTPS URL (or your own custom networking protocol that supports caching).
  • The request was successful (with a status code in the 200–299 range).
  • The provided response came from the server, rather than out of the cache.
  • The session configuration’s cache policy allows caching.
  • The provided NSURLRequestMBS object's cache policy (if applicable) allows caching.
  • The cache-related headers in the server’s response (if present) allow caching.
  • The response size is small enough to reasonably fit within the cache. (For example, if you provide a disk cache, the response must be no larger than about 5% of the disk cache size.)

Some examples using this event:

NSURLSessionMBS.didBecomeInvalid(error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
Tells the URL session that the session has been invalidated.

error: The error that caused invalidation, or nil if the invalidation was explicit.

If you invalidate a session by calling its finishTasksAndInvalidate method, the session waits until after the final task in the session finishes or fails before calling this event. If you call the invalidateAndCancel method, the session calls this event immediately.

Some examples using this event:

NSURLSessionMBS.didReceiveChallenge(challenge as NSURLAuthenticationChallengeMBS, byref disposition as Integer, byref credential as NSURLCredentialMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
Requests credentials from the delegate in response to a session-level authentication request from the remote server.

session: The session containing the task that requested authentication.
challenge: An object that contains the request for authentication.

disposition—One of several constants that describes how the challenge should be handled.
credential—The credential that should be used for authentication if disposition is NSURLSessionAuthChallengeUseCredential, otherwise nil.

This method is called in two situations:

  • When a remote server asks for client certificates or Windows NT LAN Manager (NTLM) authentication, to allow your app to provide appropriate credentials
  • When a session first establishes a connection to a remote server that uses SSL or TLS, to allow your app to verify the server’s certificate chain

If you do not implement this event, the session calls its delegate’s taskDidReceiveChallenge method instead.
Note
This method handles only the NSURLAuthenticationMethodNTLM, NSURLAuthenticationMethodNegotiate, NSURLAuthenticationMethodClientCertificate, and NSURLAuthenticationMethodServerTrust authentication types. For all other authentication schemes, the session calls only the taskDidReceiveChallenge method.

Some examples using this event:

NSURLSessionMBS.downloadTaskDidFinishDownloadingToURL(downloadTask as NSURLSessionDownloadTaskMBS, location as String, file as FolderItem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
A download task has finished downloading.

downloadTask: The download task that finished.
location: A file URL for the temporary file. Because the file is temporary, you must either open the file for reading or move it to a permanent location in your app’s sandbox container directory before returning from this event.

Some examples using this event:

NSURLSessionMBS.downloadTaskDidResumeAtOffset(downloadTask as NSURLSessionDownloadTaskMBS, fileOffset as Int64, expectedTotalBytes as Int64)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The download task has resumed downloading.

downloadTask: The download task that resumed. See explanation in the discussion.
fileOffset: If the file's cache policy or last modified date prevents reuse of the existing content, then this value is zero. Otherwise, this value is an integer representing the number of bytes on disk that do not need to be retrieved again.

In some situations, it may be possible for the transfer to resume earlier in the file than where the previous transfer ended.
expectedTotalBytes: The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is NSURLSessionTransferSizeUnknown (-1).

If a resumable download task is canceled or fails, you can request a resumeData object that provides enough information to restart the download in the future. Later, you can call downloadTaskWithResumeData with that data.

When you call those methods, you get a new download task. As soon as you resume that task, the session calls this method with that new task to indicate that the download is resumed.

Some examples using this event:

NSURLSessionMBS.downloadTaskDidWriteData(downloadTask as NSURLSessionDownloadTaskMBS, bytesWritten as Int64, totalBytesWritten as Int64, totalBytesExpectedToWrite as Int64)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
Periodically informs the delegate about the download’s progress.

downloadTask: The download task.
bytesWritten: The number of bytes transferred since the last time this event was called.
totalBytesWritten: The total number of bytes transferred so far.
totalBytesExpectedToWrite: The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is NSURLSessionTransferSizeUnknown (-1).

Some examples using this event:

NSURLSessionMBS.streamTaskBetterRouteDiscoveredForStreamTask(streamTask as NSURLSessionStreamTaskMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
A better route to the host has been detected for the stream.

streamTask: The stream task that discovered a better route.

This method is called when the URL loading system determines that a better route to the endpoint host is available. For example, this method may be called when a Wi-Fi interface becomes available.
You should consider completing pending work and creating a new stream task in order to take advantage of better routes when they become available.

NSURLSessionMBS.streamTaskDidBecomeInputStream(streamTask as NSURLSessionStreamTaskMBS, inputStream as NSInputStreamMBS, outputStream as NSOutputStreamMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The stream task has been completed as a result of the stream task calling the captureStreams method.

streamTask: The stream task that has been completed.
inputStream: The created input stream. This NSInputStream object is unopened.
outputStream: The created output stream. This NSOutputStream object is unopened

This event will only be called after all enqueued reads and writes for the stream task have been completed.

NSURLSessionMBS.streamTaskReadClosedForStreamTask(streamTask as NSURLSessionStreamTaskMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The read side of the underlying socket has been closed.

streamTask: The stream task that closed reads.

This method may be called even if no reads are currently in progress. This method does not indicate that the stream reached end-of-file (EOF), such that no more data can be read.

Some examples using this event:

NSURLSessionMBS.streamTaskWriteClosedForStreamTask(streamTask as NSURLSessionStreamTaskMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The write side of the underlying socket has been closed.

streamTask: The stream task that closed writes.

This method may be called even if no writes are currently in progress.

Some examples using this event:

NSURLSessionMBS.taskDidCompleteWithError(task as NSURLSessionTaskMBS, error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The task finished transferring data.

task: The task whose request finished transferring data.
error: If an error occurred, an error object indicating how the transfer failed, otherwise nil.

Server errors are not reported through the error parameter. The only errors your delegate receives through the error parameter are client-side errors, such as being unable to resolve the hostname or connect to the host.

Some examples using this event:

NSURLSessionMBS.taskDidFinishCollectingMetrics(task as NSURLSessionTaskMBS, metrics as NSURLSessionTaskMetricsMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The session finished collecting metrics for the task.

task: The task whose metrics have been collected.
metrics: The collected metrics.

Some examples using this event:

NSURLSessionMBS.taskDidSendBodyData(task as NSURLSessionTaskMBS, bytesSent as Int64, totalBytesSent as Int64, totalBytesExpectedToSend as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
Periodically informs the delegate of the progress of sending body content to the server.

task: The data task.
bytesSent: The number of bytes sent since the last time this event was called.
totalBytesSent: The total number of bytes sent so far.
totalBytesExpectedToSend: The expected length of the body data. The URL loading system can determine the length of the upload data in three ways:

  • From the length of the NSData object provided as the upload body.
  • From the length of the file on disk provided as the upload body of an upload task (not a download task).
  • From the Content-Length in the request object, if you explicitly set it.
Otherwise, the value is NSURLSessionTransferSizeUnknown (-1) if you provided a stream or body data object, or zero (0) if you did not.

The totalBytesSent and totalBytesExpectedToSend parameters are also available as NSURLSessionTaskMBS properties countOfBytesSent and countOfBytesExpectedToSend.

Some examples using this event:

NSURLSessionMBS.taskIsWaitingForConnectivity(task as NSURLSessionTaskMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The task is waiting until suitable connectivity is available before beginning the network load.

task: The task that is waiting for a change in connectivity.

This method is called if the waitsForConnectivity property of NSURLSessionConfigurationMBS is true, and sufficient connectivity is unavailable. The delegate can use this opportunity to update the user interface; for example, by presenting an offline mode or a cellular-only mode.

This method is called, at most, once per task, and only if connectivity is initially unavailable. It is never called for background sessions because waitsForConnectivity is ignored for those sessions.

Some examples using this event:

NSURLSessionMBS.taskWillPerformHTTPRedirection(task as NSURLSessionTaskMBS, response as NSURLResponseMBS, request as NSURLRequestMBS) as NSURLRequestMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The remote server requested an HTTP redirect.

task: The task whose request resulted in a redirect.
response: An object containing the server’s response to the original request.
request: A URL request object filled out with the new location.

Return either the value of the request parameter, a modified URL request object, or NULL to refuse the redirect and return the body of the redirect response.

This method is called only for tasks in default and ephemeral sessions. Tasks in background sessions automatically follow redirects.

Some examples using this event:

NSURLSessionMBS.webSocketTaskDidCloseWithCode(webSocketTask as NSURLSessionWebSocketTaskMBS, closeCode as Integer, reason as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The WebSocket task received a close frame from the server endpoint, optionally including a close code and reason from the server.

webSocketTask: The WebSocket task that closed.
closeCode: The close code provided by the server. If the close frame didn’t include a close code, this value is 0.
reason: The close reason provided by the server. If the close frame didn’t include a reason, this value is nil.

NSURLSessionMBS.webSocketTaskDidOpenWithProtocol(webSocketTask as NSURLSessionWebSocketTaskMBS, protocol as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
event Cocoa Networking MBS MacFrameworks Plugin 20.2 ✅ Yes ❌ No ❌ No ❌ No
The WebSocket task successfully negotiated the handshake with the endpoint, indicating the negotiated protocol.

webSocketTask: The WebSocket task that opened.
protocol: The protocol picked during the handshake phase. This parameter is nil if the server did not pick a protocol, or if the client did not advertise protocols when creating the task.

If the handshake fails, the task doesn’t call this event.

The items on this page are in the following plugins: MBS MacFrameworks Plugin.


The biggest plugin in space...