Skip to content

Preferences

Your team gives the app topics on Settings › your app › Messaging rules › Topics, such as “Offers” and “New arrivals”, each going by some of email, push, in the app and chat. A person hears about a topic by a channel only when they are subscribed to it: their own choice, or the topic’s default when they never chose. Consent and topics explains the whole model.

PurrCRM‘s emails link to a preference page on the web. In your app, you draw the screen; the SDK reads and keeps the choices. The SDK asks for no permission and decides nothing about consent: it keeps what the user chose on your screens.

Its place is .preferences (/messages/preferences), which navigate is asked to open from a link or a push. It is behind no part: anyone signed in may open it.

crm.preferences() answers a CrmPreferencesKeeper for one screen (pass wording: to name your screen’s words: below). Load it as the screen opens:

PreferencesViewController.swift
final class PreferencesViewController: UITableViewController {
private let keeper = crm.preferences()
private var watching: [CrmCancellable] = []
private var state = PreferencesState()
override func viewDidLoad() {
super.viewDidLoad()
watching.append(keeper.state.observe { [weak self] state in
self?.state = state
self?.tableView.reloadData()
})
Task { await keeper.load() }
}
// A switch in a topic's row, for one channel.
func switched(_ topic: CrmPreferenceTopic, _ channel: CrmPreferenceChannel, on: Bool) {
Task { await keeper.choose(topic.id, channel, on) }
}
@objc func unsubscribeFromAll() {
Task { await keeper.turnAllOff() }
}
}

keeper.state is a CrmValue<PreferencesState>:

FieldWhat it is
preferencesThe user’s CrmPreferences: topics, each with a name, a description and its channels (channel: .email, .push, .inApp, .chat; subscribed), and allOff. nil until read.
loading, messageReading, and why it failed.
savingHow many changes are on their way.
saveMessageWhy the last change was not kept. It is undone on screen.
keptEvery change made here is kept: say “Saved”.

Draw a switch for each topic’s channels. Each change shows at once, is sent after the ones before it (so PurrCRM keeps them in the order the user made them), and is replaced by PurrCRM‘s answer; a refusal puts back what was there and reads the choices again. turnAllOff() is “Unsubscribe from all marketing”: every channel of every topic off. A channel turned on while all marketing was off ends allOff.

Topics show in the user’s language where your team translated them. Each choice is kept with a wording id, so that PurrCRM has on record the words the user agreed under. Name your own screen’s words, and give them a new id whenever they change:

private let keeper = crm.preferences(wording: "myapp/preferences-1")

Left out (or empty), it is the SDK’s default, crmPreferencesWording (crm_sdk/preferences-1, the words of the Flutter package’s own preferences screen). At most 100 characters. Whatever the id, your screen’s words should say what the switches do: a topic by a channel, and one way to turn all marketing off.

The push channel has its own switch above every topic: a marketing push goes only to people who agreed to offers by push. If your app asks them, tell PurrCRM, and read it back for your own switch:

let kept = await crm.setOffersByPush(true) // the consent as kept, or nil
let agreed = await crm.offersByPush() // nil when it could not be read

Both answer nil when PurrCRM could not be reached. Asking the phone for the notification permission is separate, and yours (Push).