Skip to content

Built-in screens

CrmSdk on its own draws nothing: your app reads its state and draws every screen. If you’d rather not, add CrmSdkUI, the SDK’s built-in screens, written in UIKit. They open over your app the way a support messenger usually does: the messenger and its conversations in a sheet, and your in-app messages as banners, sheets and cards.

You can use them for everything, for some places only, or not at all.

  1. In Xcode, open your target’s General › Frameworks, Libraries, and Embedded Content, and add the CrmSdkUI library from the same package as CrmSdk. It runs on iOS 13 and later, and has no dependencies of its own.

  2. Install it once, after you’ve made the Crm, set its host and started it:

    AppDelegate.swift
    import CrmSdk
    import CrmSdkUI
    crm.start()
    CrmUI.install(crm)

That’s all. From now on, every way into PurrCRM‘s pages opens the built-in screen: crm.open(...), a tapped push, a link, and the setup check.

Call these from a button in your app:

CrmUI.current?.presentMessenger() // the messenger's first screen
CrmUI.current?.presentNewConversation() // a new conversation, ready to type in
CrmUI.current?.presentConversation(id) // one conversation
CrmUI.current?.presentHelpCenter() // the help center, with its search
CrmUI.current?.presentCollection(slug) // one collection of articles
CrmUI.current?.presentArticle(slug) // one article
CrmUI.current?.presentTickets() // the signed-in user's tickets
CrmUI.current?.presentTicket(id) // one ticket
CrmUI.current?.presentPreferences() // which messages they get, and how
CrmUI.current?.presentInbox() // the notices you sent them, newest first
CrmUI.current?.dismiss() // close them all, back to your app

The inbox has no link of its own, so open it from your app, from a bell for example. It needs someone signed in: presentInbox() returns false otherwise.

To show one carousel, survey or post at a moment of your choosing (after a purchase, say), call it by its id. The id is on the message’s page on PurrCRM.

CrmUI.current?.presentCarousel(id) // a carousel your team made
CrmUI.current?.presentSurvey(id) // a survey
CrmUI.current?.presentPost(id) // a post
CrmUI.current?.presentMessage(id) // any in-app message, whatever its kind

The SDK asks PurrCRM for that message and shows it next, even if no check-in brought it. It still waits until you call crm.setReady(true), and nothing shows if the message isn’t meant for the signed-in user.

The message must be set to show Only when its link is opened on PurrCRM. A message that shows on its own when people check in can’t be called up by its id.

With the built-in screens installed, your in-app messages come in over your app as they arrive:

  • a banner slides in across the top, without moving your layout. A tap anywhere else still reaches your screen, and people swipe it away;
  • a post, a survey or a carousel opens as a sheet, a card or the whole screen, as your team chose on PurrCRM.

They still wait until you call crm.setReady(true), so they never cover your sign-in or onboarding steps. Everything people do with them is reported to PurrCRM as usual.

The screens are drawn in a window of their own, above your app’s and below its alerts. Your app’s own screens and navigation stay as they are.

Pass CrmUIOptions to install:

CrmUI.install(
crm,
options: CrmUIOptions(
places: [.messenger, .conversation, .newConversation],
presentMessages: true,
theme: CrmUITheme(accent: UIColor(red: 0.06, green: 0.46, blue: 0.43, alpha: 1)),
launcher: .site
)
)
  • places: the pages the SDK draws. A page you leave out goes to your own CrmHost.navigate, as it would without the built-in screens.
  • presentMessages: set it to false to draw your in-app messages yourself (see In-app messages) while the SDK draws the messenger.
  • theme: the accent colour, light or dark (darkMode), the fonts, the corners (corner), the buttons’ shape (buttonShape) and the animation (motion). Leave a part out and it comes from the look your team published (see below).
  • launcher: whether the launcher shows: .site (as your team chose, the default), .always or .never.
  • imageLoader: your own picture loader, if your app already has one.

Set crm.host before you install: a host you set afterwards replaces the built-in screens’ navigation.

Your team can style the built-in screens on PurrCRM, under Settings › your app › Messenger: the colours, the corners and buttons, light or dark, the messenger’s header and words, the launcher, and the animation (see Style the messenger and messages). The screens follow it the next time the app opens, with no new release.

Anything you set in code wins. Each part of the look comes from, in order:

  1. your theme, where you set that part;
  2. the look your team published on PurrCRM;
  3. the SDK’s own default.

So CrmUITheme(accent: …) keeps your accent and takes everything else from PurrCRM. When the phone is set to Reduce Motion, nothing animates, whatever the look or your theme says.

When your team turns the launcher on, a round button floats over your app’s screens. It opens the messenger and shows how many messages are unread. It puts itself away while the messenger, a message or the keyboard is up, and never shows over PurrCRM‘s own screens.

To keep it off one of your screens, a full-screen video say:

CrmUI.current?.hideLauncher() // in viewWillAppear
CrmUI.current?.showLauncher() // in viewWillDisappear

The messenger’s screens are public view controllers too, to push in your own navigation controller:

navigationController?.pushViewController(CrmMessengerViewController(crm: crm), animated: true)

The screens’ words are in a strings table called CrmSdkUI, in English. To word one differently, or to add a language, add a CrmSdkUI.strings file to your app with the same keys: your app’s words win, key by key.