Overview
In-app messages arrive in your app as data, not as finished screens. The SDK keeps a local inbox of each user’s messages up to date and calls your code when it changes. Your app picks the messages for a screen, lays them out with its own views, and reports what the user did with them. Each message carries the fields from its template, such as a headline, an image URL, and a button label, keyed by the names your marketing team agreed with you. See What your app receives.Before you begin
- Push setup: Complete Set up iOS push notifications through Identify users on login and logout. The SDK fetches a user’s messages only for a device that has registered a push token and called
identify. - iOS 13 or later: In-app messages need
HightouchPushversion 1.1.0 or later. - A template: Agree with your marketing team on the templates your app supports, and the key of each field. See Build an in-app template.
Turn on in-app messages
Add aHightouchMessagesConfig to the HightouchPushConfig you already pass to HightouchPush.initialize, in application(_:didFinishLaunchingWithOptions:):
initialize synchronously in didFinishLaunchingWithOptions. If a silent push launches the app before initialize runs, the SDK ignores the push.
HightouchMessagesConfig takes these options:
Turn on
syncOnForeground unless your app relies on silent pushes alone. Without it, the SDK doesn’t fetch new messages for a user who keeps the app in the background until the next launch or silent push.
Keep the inbox up to date
The SDK fetches messages:- When the app launches, if
syncOnLaunchis on. - When the app returns to the foreground, if
syncOnForegroundis on. - When a user logs in with
HightouchPush.identify. - When a silent push arrives from Hightouch, if the message has push apps selected. See Refresh inboxes right away.
HightouchAppIntegration.application(_:didReceiveRemoteNotification:fetchCompletionHandler:) in your app delegate, and keep the Remote notifications background mode turned on.
To fetch messages yourself, such as on pull to refresh, call sync:
Show messages in your app
Load the messages for a screen withloadMessages, which calls back on the main thread. Filter by the template’s Location ID to get the messages for one placement:
HightouchMessageQuery also takes variantSlug, the template’s key, to load only messages built from one template. To read synchronously, call HightouchMessages.messages(matching:). It can block while the store opens, so prefer loadMessages on the main thread.
Read the fields from the message’s content. Each element’s tag is a field key from the template:
elements. Give your views a fallback for every optional field.
Report impressions, clicks, and dismissals
The SDK doesn’t know when your app shows a message, so report each interaction yourself. These events power the Impressions, Clicked, and Dismissed metrics in Hightouch, and they’re written to your warehouse.identifier to trackClick to tell buttons apart in your warehouse data. It defaults to default.
trackDismissed removes the message from the device, and Hightouch removes it from the user’s other devices. The user doesn’t receive that message again, even if they leave and rejoin the audience.
Tips and troubleshooting
No messages arrive
The SDK skips a sync when the user isn’t identified or the device has no push token. Check that:- Your app calls
HightouchPush.register(token:)with the APNs device token, andHightouchPush.identifyafter the user logs in. Users who aren’t logged in don’t receive in-app messages. - The user ID matches the primary key of the profile in your Delivery parent model.
- The profile is in the campaign’s audience, or has reached the journey’s Send in-app tile, and the campaign or journey is running.
HightouchMessages.sync(force: true) and check the outcome. If it returns .unchanged, the SDK either found no changes or skipped the sync because the user isn’t identified or the device has no push token.
A new message takes a while to appear
Without a push app on the message, a device picks it up on its next sync. Turn onsyncOnForeground, or ask your marketing team to select push apps on the message.
Messages stop updating after a while
The SDK keeps a weak reference to your delegate. If nothing else holds it, it’s released and your app stops hearing about changes. Store the delegate in a static or long-lived property.Next steps
- Build an in-app template: the fields and keys your app reads.
- Send an in-app campaign: send a message to your test profile to check the integration end to end.