Getting upload status for tunneled HTTP/S requests

The AppConnect library and the MobileIron client app are responsible for tunneling network connections using AppTunnel with HTTP/S tunneling.

The AppConnect for iOS SDK includes APIs that provide upload status for HTTP/S requests. Use these APIs only if your app uses both of the following:

the AppTunnel with HTTP/S tunneling feature
the NSURLConnectionDataDelegate method
-connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:

or the NSURLSessionTaskDelegateMethod

-URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:

These methods provide upload status for HTTP/S requests.

AppConnect library behavior when using AppTunnel

Apps that access enterprise servers using NSURLConnection or NSURLSession can use AppTunnel with HTTP/S tunneling, as described in AppTunnel. The AppConnect library determines which URLs to tunnel based on the MobileIron server configuration, and creates the secure tunnel for HTTP/S requests to and responses from a server behind an organization’s firewall.

One aspect of this AppTunnel handling is that the AppConnect library intercepts the following NSURLConnectionDataDelegate and NSURLSession methods:

-connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:
 
-URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:

This interception means that if your app has implemented the NSURLConnectionDataDelegate or NSURLSessionTaskDelegate protocol, your implementation of these methods is never called. If the app depends on this method, for example, to show the progress of an HTTP/S upload, that functionality will not work properly.

Therefore, the AppConnect for iOS SDK provides APIs to support showing the progress of an HTTP/S upload when using AppTunnel with HTTP/S tunneling.

Upload status API overview

The AppConnect for iOS API provides a mechanism for the app to receive the upload status when an HTTP/S request is tunneled using AppTunnel with HTTP/S tunneling. The mechanism uses:

The AppConnectNetworkingDelegate protocol that you implement to receive HTTP/S upload progress data
A category method called -setNetworkingDelegate: in the Networking category on the AppConnect interface. The app uses -setNetworkingDelegate: to tell the AppConnect object about the object of the class that implements the AppConnectNetworkingDelegate protocol.

The protocol and the category are defined in AppConnect+Networking.h.

The AppConnectNetworkingDelegate protocol

Implement the AppConnectNetworkingDelegate protocol to receive HTTP/S upload progress data about tunneled requests. This protocol contains one method that provides an estimate of the progress of the upload.

-(void) uploadProgressForConnectionWithURLRequest:(NSURLRequest *)request
                       bytesWritten:(NSInteger)bytesWritten
                       totalBytesWritten:(NSInteger)totalBytesWritten
	               totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;

The AppConnect library calls this method after it intercepts the following NSURLConnectionDataDelegate or NSURLSessionTaskDelegate methods:

-connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:
 
-URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:

The AppConnectNetworkingDelegate protocol method provides the following information in its parameters:

the number of bytes written in the latest write
the total number of bytes written for the connection with this request
the number of bytes the connection expects to write

The -setNetworkingDelegate: method

The Networking category of the AppConnect interface provides the method -setNetworkingDelegate:. If your app requires HTTP/S upload progress data on tunneled HTTP/S requests, call this method before sending the HTTP/S request.

For example:

[[AppConnect sharedInstance] setNetworkingDelegate:myNetworkingDelegate];

where myNetworkingDelegate is an instance of a class that implements the AppConnectNetworkingDelegate protocol.