Getting Started with Preference Center

Preference Center allows users to opt in and out of subscription lists configured via the Airship Dashboard. For more information, see the Preference Center user guide.

 Important

Airship preference centers are widgets that can be embedded in a page in an app or website. Please verify with your legal team that your full preference center page, including any web page for email preference centers, is compliant with local privacy regulations.

Displaying a Preference Center

A Preference Center can be displayed in its own window with the provided Airship UI with a single method call. By wiring this method call to a button in your app, you can quickly produce a user-initiated Preference Center with no additional effort.

Displaying a Preference Center

PreferenceCenter.shared().open("my-first-pref-center")
PreferenceCenter.shared().open("my-first-pref-center");
PreferenceCenter.shared.open("my-first-pref-center")
[[UAPreferenceCenter shared] openPreferenceCenter:@"my-first-pref-center"];
UrbanAirship.openPreferenceCenter("my-first-pref-center")
Airship.openPreferenceCenter("my-first-pref-center");
UAirship.openPreferenceCenter("my-first-pref-center")
// Not supported in NetStandard library. Use native binding methods instead.
Airship.preferenceCenter.display("my-first-pref-center")
// Not supported

Styling the Preference Center

Most developers will want to customize the look and feel to match their app’s existing style and layout. iOS and Android both support customizing through a styling config:

Custom Preference Centers

If the provided preference center is insufficient for your app, you can build your own UI. Currently, preference center is limited to modifying subscription lists. You will need to fetch and edit lists when the user interacts with the preferences. See the susbscription list audience section for more info on to interact with subscription lists.

Example preference center implementations are available in our open source repos:

Fetching Preference Center config

When creating a custom preference center, you will need to fetch the config from the Airship SDK. The config might not be available right away on first app start. Screens should use exponential back off if automatically retrying, or provide a UI to the user to retry.

Fetching config

val configPendingResult = PreferenceCenter.shared().getConfig(preferenceCenterId)
PendingResult<PreferenceCenterConfig> configPendingResult = PreferenceCenter.shared().getConfig(preferenceCenterId);
PreferenceCenter.shared.config(preferenceCenterID: preferenceCenterId) { config in
    // Use the preference center config
}
[[UAPreferenceCenter shared] configForPreferenceCenterID:preferenceCenterId completionHandler:^(UAPreferenceCenterConfig * _Nullable config) {
    // Use the preference center config
}];
AirshipPreferenceCenter.getConfiguration(preferenceCenterId).then((config) => {
    // Use the preference center config
});
PreferenceCenterConfig preferenceCenterConfig = await Airship.getPreferenceCenterConfig(preferenceCenterId)
UAirship.getPreferenceCenterConfig(preferenceCenterId, function(result) {
    //Use the preference center config
})
// Not supported in NetStandard library. Use native binding methods instead.
Airship.preferenceCenter.getConfig(preferenceCenterConfig function(result) {
    //Use the preference center config
})
// Not supported

Overriding the open behavior

To override the default preference center handling, you need to set a delegate/listener to handle displaying the preference center and to prevent the Airship SDK from displaying the OOTB UI.

Override Preference Center Display

Set the PreferenceCenterOpenListener during the onAirshipReady callback.

PreferenceCenter.shared().openListener =  object : PreferenceCenter.OnOpenListener {
    override fun onOpenPreferenceCenter(preferenceCenterId: String): Boolean {
      // Navigate to custom preference center UI

      // true to prevent default behavior
      // false for default Airship handling
      return true
    }
}

Set the PreferenceCenterOpenListener during the onAirshipReady callback.

PreferenceCenter.shared().setOpenListener(preferenceCenterId -> {
    // Navigate to custom preference center UI

    // true to prevent default behavior
    // false for default Airship handling
    return true;
});

Set the delegate after takeOff.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PreferenceCenterOpenDelegate, ... {
    
    ...

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        ...

        // Call takeOff
        Airship.takeOff(config, launchOptions: launchOptions)

        // Set the Preference Center open delegate
        PreferenceCenter.shared.openDelegate = self

        return true
    }

    func openPreferenceCenter(_ preferenceCenterID: String) -> Bool {
        // Navigate to custom preference center UI

        // true to prevent default behavior
        // false for default Airship handling
        return true
    }

    ...
}

Set the delegate after takeOff.

@interface AppDelegate() <UAPreferenceCenterOpenDelegate, ...>

...

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    ...

    // Call takeOff
    [UAirship takeOff:config launchOptions:launchOptions];

    // Set the Preference Center open delegate
    UAPreferenceCenter.shared.openDelegate = self;

    return Yes;
}


- (BOOL)openPreferenceCenter:(NSString *)preferenceCenterID {

    // YES to prevent default behavior
    // NO for default Airship handling
    return YES;
}
...

@end
// Set which preference centers to handle
AirshipPreferenceCenter.setUseCustomPreferenceCenterUi(true, preferenceCenterId);
AirshipPreferenceCenter.addPreferenceCenterOpenListener((e) => {
  // Navigate to custom preference center UI
  console.log("Open preference center: " + e.preferenceCenterId)
})
Airship.setAutoLaunchDefaultPreferenceCenter(true);
Airship.onShowPreferenceCenter
    .listen((preferenceCenterId) => debugPrint('Open preference center $preferenceCenterId'));
UAirship.setUseCustomPreferenceCenterUi(preferenceCenterId, true)
document.addEventListener("urbanairship.open_preference_center", function(e)  {
  // Navigate to custom preference center UI
  console.log("Open preference center: " + e.preferenceCenterId)
}
// Not supported
Airship.preferenceCenter.setUseCustomPreferenceCenter(preferenceCenterId, true)
Airship.addEventListener(Airship.eventOpenPreferenceCenter, function (e) {
    // Navigate to custom preference center UI
    console.log("Open preference center: " + e.preferenceCenterId)
});
// Not supported