Skip to main content

Pre-Requisites

Understanding preference structure

This is how a typical preference page will look like:
Description
Preference Page contains 2 sections:
  1. Category-level preference settings (Sections)
  2. Overall Channel-level preference
Description

Preferences data structure

1.1 Sections

This contains the name, description, and subcategories. We have to loop through the sections list and for every section item if there is a name and description present, then show the heading, and if a subcategories list is present, loop through that subcategories list and show all subcategories under that section heading. Subcategories can exist without sections as the section is an optional field. In that case, the section’s name will not be available. For sections where the name is not present, you can directly show its subcategories list without showing Heading for the section in UI.

1.2 Categories (sections -> sub-categories)

This is the place where the user sets his category-level preferences. While looping through the subcategories list for every subcategory item, show the name and description in UI.

1.3 Category channels (sections -> sub-categories -> channels)

This contains a list of channels, channel preference status and whether it’s editable or not. While looping through the subcategory list for every subcategory item we have to loop through its channels list and for every channel to show channel level checkbox.
Description

2. Overall channel preferences

It’s a list of all channel-level preferences. We have to loop through the list and for each item, show the UI as given in the below image.
Description

Integration

Get preferences data

Use this method to get preferences data and create the preferences UI by following the above sections. This method should be called first before any update preference methods.
If you are passing tenantId in preferences (or have set it via identify / changeTenant), make sure that tenant is included in the scope.tenant_id key while creating userToken passed during identifying user, else an error will be thrown due to scope mismatch.
Returns: async -> PreferenceAPIResponse

Update channel preference in category

Calling this method will opt-in/opt-out users from that category-level channel. When the category’s channel checkbox is editable and the user clicks on the checkbox you can call this method.
Returns: async -> PreferenceAPIResponse
Description

Update category preference

This is category level preference changing method. Calling this method will opt-in/opt-out user from that category. When the category is editable and the switch is toggled you can call this method.
Returns: async -> PreferenceAPIResponse

Update overall channel preference

This method updated the channel-level preference of the user.
Returns: async -> PreferenceAPIResponse
Description

Event listeners

All preferences update api’s are optimistic updates. Actual API call will happen in background with 1 second debounce. Since its a background task SDK provides event listeners to get updated preference data based on API call status. Listen to this event listeners and update the UI accordingly.

Example

Preferences UI example code: PreferencesView.swift and PreferenceModel.swift