Updatable Configuration API

Prev Next

For conceptual information about this feature, see Integration of the Automatic Configuration Update.

Using the ShieldSDK APIs, you can manually request an updated configuration instead of waiting for an unexpected termination of the app to trigger the update. The APIs also allow you to set the custom identifier for the X-update-custom-id header and receive callbacks when the app successfully downloads a new configuration. If set, the custom identifier must be a valid HTTP header value. App Shielding will not send HTTP headers with invalid characters. Therefore, it is recommended that custom identifiers use Base64 or Base16 (i.e., hex) encoding.

Integration of the iOS SDK API

First, add the ShieldSDK.xcframework bundle from the App Shielding package to your iOS project and include the ShieldSDK/Shield.h header.

You can then use the ShieldConfig class with the following methods:

Method

Description

requestUpdate

Triggers App Shielding to check for and download a configuration update.

getActiveConfigTimestamp

Retrieves the internal timestamp value of the currently active configuration. App Shielding uses this timestamp as a unique identifier to ensure that the newest available configuration is activated on app launch. Thus, it is possible that an update with a newer timestamp has been downloaded but is not yet active.

setUpdateCustomId:

Sets the X-update-custom-id header for configuration requests. The provided NSData is stored and used for any future request to the server, even after restarting the application. To clear the custom ID (i.e., not use the X-update-custom-id header), pass nil as the token.

setUpdateCallbacks:

Registers a listener that is invoked whenever App Shielding downloads a configuration update. The callback receives a time stamp value that reflects the embedded time stamp from the downloaded configuration. This method can only be called once.

The following example demonstrates how these methods can be used:

[ShieldConfig requestUpdate];
[ShieldConfig setUpdateCustomId:[NSData dataWithBytes:"my-token" length:8]];

For callbacks, you can start with the ConfigUpdateCallbacks interface.

@interface ConfigUpdateCallbacks : NSObject <ShieldConfigUpdateCallbacks>
        @end

        @implementation ConfigUpdateCallbacks
        - (void)configUpdateReceived:(NSString *)timestamp
        {

        // handle callback logic
        ...
        }
        @end

During the app initialization (e.g., in didFinishLaunchingWithOptions), call the setUpdateCallbacks method in the following manner:

[ShieldConfig setUpdateCallbacks:[[ConfigUpdateCallbacks alloc] init]];

Swift example

If you are using Swift instead of Objective-C, you can set up the callback as follows:

clclass ConfigUpdateCallbacks: NSObject, ShieldConfigUpdateCallbacks {
    func configUpdateReceived(_ timestamp: String) {
        // handle callback logic
        ...
    }
}

...
ShieldConfig.setUpdateCallbacks(ConfigUpdateCallbacks())

You should be aware that the downloaded new configuration is not applied immediately, but only after an application is restarted.