Skip to content

Latest commit

 

History

History
224 lines (184 loc) · 6.27 KB

Preferences.md

File metadata and controls

224 lines (184 loc) · 6.27 KB
ios-preferences-banner

Courier Preferences

In-app notification settings that allow your users to customize which of your notifications they receive. Allows you to build high quality, flexible preference settings very quickly.

Requirements

Requirement Reason
Authentication Needed to view preferences that belong to a user.

Usage

CourierPreferences works with all native iOS UI frameworks.

UI Framework Support
UIKit
XIB ⚠️ Not optimised
SwiftUI

Default Preferences View

The default CourierPreferences styles.

default-inbox-styles
import Courier_iOS

// UIKit

// Create the view
let courierPreferences = CourierPreferences(
    mode: .topic,
    onError: { error in
        print(error.localizedDescription)
    }
)

// Add the view to your UI
courierPreferences.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(courierPreferences)

// Constrain the view how you'd like
NSLayoutConstraint.activate([
    courierPreferences.topAnchor.constraint(equalTo: view.topAnchor),
    courierPreferences.bottomAnchor.constraint(equalTo: view.bottomAnchor),
    courierPreferences.leadingAnchor.constraint(equalTo: view.leadingAnchor),
    courierPreferences.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])

// SwiftUI

var body: some View {
    CourierPreferencesView(
        mode: .topic,
        onError: { error in
            print(error.localizedDescription)
        }
    )
}

Styled Preferences View

The styles you can use to quickly customize the CourierPreferences.

default-inbox-styles
import Courier_iOS

let textColor = UIColor(red: 42 / 255, green: 21 / 255, blue: 55 / 255, alpha: 100)
let primaryColor = UIColor(red: 136 / 255, green: 45 / 255, blue: 185 / 255, alpha: 100)
let secondaryColor = UIColor(red: 234 / 255, green: 104 / 255, blue: 102 / 255, alpha: 100)

// Theme object containing all the styles you want to apply 
let preferencesTheme = CourierPreferencesTheme(
    brandId: "7S9R...3Q1M", // Optional. Theme colors will override this brand.
    loadingIndicatorColor: secondaryColor,
    sectionTitleFont: CourierStyles.Font(
        font: UIFont(name: "Avenir Black", size: 20)!,
        color: .white
    ),
    topicCellStyles: CourierStyles.Cell(
        separatorStyle: .none
    ),
    topicTitleFont: CourierStyles.Font(
        font: UIFont(name: "Avenir Medium", size: 18)!,
        color: .white
    ),
    topicSubtitleFont: CourierStyles.Font(
        font: UIFont(name: "Avenir Medium", size: 16)!,
        color: .white
    ),
    topicButton: CourierStyles.Button(
        font: CourierStyles.Font(
            font: UIFont(name: "Avenir Medium", size: 16)!,
            color: .white
        ),
        backgroundColor: secondaryColor,
        cornerRadius: 8
    ),
    sheetTitleFont: CourierStyles.Font(
        font: UIFont(name: "Avenir Medium", size: 18)!,
        color: .white
    ),
    sheetSettingStyles: CourierStyles.Preferences.SettingStyles(
        font: CourierStyles.Font(
            font: UIFont(name: "Avenir Medium", size: 18)!,
            color: .white
        ),
        toggleColor: secondaryColor
    ),
    sheetCornerRadius: 0,
    sheetCellStyles: CourierStyles.Cell(
        separatorStyle: .none
    )
)

// UIKit

// Pass the theme to the view
let courierPreferences = CourierPreferences(
    mode: .channels([.push, .sms, .email]),
    lightTheme: preferencesTheme,
    darkTheme: preferencesTheme,
    onError: { error in
        print(error.localizedDescription)
    }
)

view.addSubview(courierPreferences)
...

// SwiftUI

var body: some View {
    CourierPreferencesView(
        mode: .topic,
        lightTheme: preferencesTheme,
        darkTheme: preferencesTheme,
        onError: { error in
            print(error.localizedDescription)
        }
    )
}

Courier Studio Branding (Optional)

setting

You can control your branding from the Courier Studio.

Supported Brand Styles Support
Primary Color
Show/Hide Courier Footer

👋 Branding APIs can be found here

👋 Preference APIs can be found here