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 SDK/C/ShieldSDK.xcframework bundle from the App Shielding package to your project and include the ShieldSDK/config_update.h header. You can then use the following functions:

Function

Description

prm_config_request()

Triggers App Shielding to check for and download a new configuration. The request is performed in the background, so the function returns immediately.

prm_config_timestamp()

Retrieves the internal timestamp value of the currently active configuration as an int64_t. 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

prm_config_set_id(id)

Sets the X-update-custom-id header for configuration requests. The provided C string is stored and used for any future requests to the server, even after restarting the application. The call fails if the string contains any characters outside the printable ASCII range (0x20-0x7e), and the failure is not reported back to the caller. To clear the custom ID (i.e., not use the X-update-custom-id header), pass NULL.

prm_config_set_cb(ctx, cbs)

Registers a callback struct with a downloaded event that is invoked whenever Shield downloads a config update. The callback receives the registered context pointer and the internal timestamp of the downloaded configuration. This function can only be called once and returns false if it has already been called.

When using the downloaded callback, be mindful of the following:

  • The callback might be called on an arbitrary thread. Dispatch to the main queue before performing any UI work from it.

  • The callback cannot be unregistered, so the context pointer passed to prm_config_set_cb() must remain valid for the lifetime of the application.

Example

The following example sets a custom ID, registers a callback, and requests an update:

#include <ShieldSDK/config_update.h>
...

static void
on_config_downloaded(void *ctx, int64_t timestamp)
{
    (void)ctx;

    // handle callback logic
    ...
}

void
shield_config_init(void)
{
    struct prm_config_cbs cbs = {
        .downloaded = on_config_downloaded,
    };

    prm_config_set_cb(NULL, cbs);
    prm_config_set_id("my-token");
    prm_config_request();
}