Skip to content
Menu

In-app messages

Controlling display

Markdown version

Use the in-app message delegate to show, hold or drop a message, show held messages with showNext, and keep messages away from onboarding and checkout.

Set a delegate to decide, message by message, whether it shows now, waits, or is dropped. Use it to keep messages out of flows where an interruption costs you, such as onboarding, checkout or a video.

Before you start

  • The default presenter, or your own, is installed. See the overview.

1. Set a delegate

The delegate returns one of three choices:

ChoiceiOSAndroidEffect
Show now.displayInAppDisplayDecision.DISPLAYThe message appears.
Later.laterInAppDisplayDecision.LATERThe message stays pending. It is offered again automatically, or at once with showNext().
Drop.discardInAppDisplayDecision.DISCARDThis occurrence is dropped. Nothing is recorded, so the message stays eligible for its next trigger.

With no delegate, every message shows.

swift
import HeraldSDK

@MainActor
final class MessageGate: InAppMessageDelegate {
    static let shared = MessageGate()
    var isBusy = false

    func shouldDisplay(_ message: InAppMessage) -> InAppMessageDisplayChoice {
        if isBusy { return .later }
        // Never interrupt with a full-screen takeover; a banner is fine.
        if message.type == .full { return .discard }
        return .display
    }
}

// At launch, after configure. The SDK holds the delegate weakly: keep a strong reference.
Herald.shared.inAppMessageDelegate = MessageGate.shared

Threading. The delegate runs on the main thread on both platforms (the main actor on iOS). Return quickly. If an Android delegate throws, the SDK shows the message and logs the error.

When it is asked. The delegate is asked when a message is about to appear, not when its trigger fires, so it sees your app's state at that moment. It can be asked more than once for the same message: after a later, and when it answered show now but there was no screen to draw on. Keep it free of side effects such as analytics calls.

2. Hold messages during onboarding or checkout

Set your flag when the sensitive flow starts. When it ends, clear the flag and call showNext() to show the message that waited.

swift
func checkoutDidStart() {
    MessageGate.shared.isBusy = true
}

func checkoutDidFinish() {
    MessageGate.shared.isBusy = false
    Herald.shared.showNext()
}

showNext() offers the highest-priority waiting message now, ignoring the minimum interval; on a tie, the one that has waited longest. Your delegate is asked again. It does nothing while another message is on screen or when nothing is waiting.

You do not have to call showNext(). A message held with later is also offered again on its own the next time the app comes to the foreground, a trigger fires or a message closes. showNext() makes it show as soon as your flow ends instead.

3. Route message clicks (iOS)

Button and body clicks open their URL through Herald.shared.openDeepLink(_:). Set deepLinkHandler to route your own links inside the app; return true when you handled the URL, false to let the system open it.

swift
Herald.shared.deepLinkHandler = { url in
    guard url.scheme == "lumen" else { return false }
    AppRouter.shared.open(url)
    return true
}

On Android, clicks go to Herald.deepLinkHandler first, with the same semantics. When it is null or returns false, the SDK opens the link with an ACTION_VIEW intent, so register your scheme with an intent filter on the activity that should handle it.

Verify it works

  1. Set the busy flag and trigger a message (for example with a session start). Nothing appears.
  2. Clear the flag and call showNext(). The message appears.
  3. With debug logging on, a dropped message logs discarded by delegate on Android. On iOS nothing is logged for a drop.

Troubleshooting

  • The delegate is never called (iOS). The SDK keeps a weak reference. If nothing else holds your delegate object, it is released right after you assign it.
  • A held message shows later than expected. It is offered again at the next foreground, trigger or close. Call showNext() when your flow ends to show it at once.
  • A message shows during checkout anyway. The message was already on screen when the flow started. Set the flag before the flow's first screen appears.

Next

See Herald decide live →