Callback method involving network requests with AppTunnel

Overview of network requests when using AppTunnel

A wrapped app can use MobileIron AppTunnel, as described in Tunneling, to securely tunnel HTTP and HTTPS network connections from the app to servers behind a company’s firewall. An administrator configures the MobileIron server with the AppTunnel rules for the app. The AppTunnel rules specify which URL requests to tunnel.

When an app first launches:

1. Control switches to the MobileIron client app (Mobile@Work for MobileIron Core, MobileIron Go for MobileIron Cloud).
2. The MobileIron client app gets the configuration and policy settings for the app, including the AppTunnel rules, from the MobileIron server.
3. The MobileIron client app delivers the settings to the AppConnect library in the app.
4. Control switches back to the app.

When the app makes a network request, such as when loading a web view, the AppConnect library determines if the URL matches one of the AppTunnel rules. If a match is found, the AppConnect library tunnels the request.

Therefore, if an app makes network requests before the AppConnect library has received the AppTunnel rules, the network requests will fail for URLs behind the enterprise’s firewall.

When this occurs, an app should try the request again. For example, the app can try the request again after some time has elapsed, or the next time it becomes active.

Alternatively, an app can wait to make a network request until after the AppConnect library has received the AppTunnel rules. An AppConnect wrapper callback method is available for the app to know when the rules have been received.

Wrapper callback method for when to send network requests

You can use the following callback method to make sure your wrapped app does not send a network request until after the AppConnect library in the app has received the AppTunnel rules. Implement the method on the class that implements the UIApplicationDelegate protocol.

In Objective-C:

 

-(void)appConnectStateChangedTo:(NSInteger)newState;

In Swift:

 

@objc func appConnectStateChangedTo(_ newState: Int)

 

When in the app life cycle the AppConnect library calls -appConnectStateChangedTo:

The AppConnect library calls the -appConnectStateChangedTo: method when:

the app is first launched.
the app is launched after being terminated.
the app is launched after the device is restarted.

In these situations, the AppConnect library calls the method when the library has either:

Received the AppTunnel rules.
Determined that it will not receive the AppTunnel rules because the MobileIron client app is not installed on the device.

Without the MobileIron client app, the wrapped app does not run as an AppConnect app. No AppConnect features are available to it.

NOTE: When an app is unauthorized, the MobileIron client app displays a message and the app exits. In that case, the AppConnect library does not call the -appConnectStateChangedTo: method.

The -appConnectStateChangedTo: method parameter

The following table shows the possible values of the newState parameter in the -appConnectStateChangeTo: method:

Value of newState

Meaning of value

Action your app takes

0

The AppConnect library in the app will not receive AppTunnel rules because the MobileIron client app is not installed on the device.

Without the MobileIron client app, the wrapped app does not run as an AppConnect app. No AppConnect features are available, including AppTunnel. Network requests to URLs behind a firewall will fail.

Behave as a standard, non-AppConnect app. Typically, this requires no changes to your app.

1

The AppConnect library in the app has received the AppTunnel rules.

The app can now make network requests that will be tunneled.

AppConnectStateChangedTo callback method in Xamarin apps

Wrapped Xamarin apps can use a callback method to determine when to send network requests that use AppTunnel. Specifically, the developer implements the following method in the UIApplicationDelegate class or subclass:

[Export ("appConnectStateChangedTo:")]
 
public AppConnectStateChangedTo (System.nint newState) {
 
	// newState parameter:
	//
	// 0 - The AppConnect library in the app will not receive AppTunnel rules, 
	// 	 or any other AppConnect configurations and policies, because
	// 	the MobileIron client app is not installed on the device. 
	// 	Network requests to URLs behind a firewall will fail.
	// 	The app should behave 	as a standard, non-AppConnect app.
	//
	// 1 - The AppConnect library in the app has received the AppTunnel rules. The app can
	//	now make network requests that will be tunneled. 
 
}