Overview
Quickstart: iOS
Add the Herald SDK to an iOS app, identify a user, track an event, register for push and show content cards.
This guide takes an iOS app from no SDK to a verified first event, a registered push token and the default content card feed. It takes about 30 minutes.
Before you start
- An app that targets iOS 16 or later, built with Xcode 16 or later.
- A Herald sending connection with an app key. In Herald, open Settings > Sending, open the connection and find the Mobile SDK card. If it has no key, click Generate app key. The card also shows your endpoint URL.
- A backend route that returns a user token for the signed-in user, unless identity verification is Off. See Users and identity.
- For push: an APNs auth key on the connection. See iOS push setup.
1. Add the package
In Xcode, choose File > Add Package Dependencies, enter https://github.com/ender1311/herald-ios, choose version 0.6.0 or later, and add the HeraldSDK and HeraldUI libraries to your app target. For a Package.swift manifest, Platform support has the lines.
2. Configure the SDK at launch
Call Herald.configure once, as early as possible. Debug logging helps while you integrate; remove it before release.
import SwiftUI
import UserNotifications
import HeraldSDK
import HeraldUI
@main
struct LumenApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene { WindowGroup { HomeView() } }
}
final class AppDelegate: NSObject, UIApplicationDelegate, @preconcurrency UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
Herald.configure(appKey: "YOUR_APP_KEY", endpoint: URL(string: "https://YOUR_HERALD_HOST")!) { options in
options.logLevel = .debug
}
Herald.useDefaultInAppUI() // default in-app message views
UNUserNotificationCenter.current().delegate = self
return true
}
}Every SDK call returns at once and runs in the background, in the order you made it. Calls made before configure are kept and applied once it runs.
3. Identify the user
After sign-in, call identify with your stable External ID, then setUserToken with the token your backend returns. Call them in that order: identifying a different user clears the previous token.
func didSignIn(userId: String, userToken: String) {
Herald.shared.identify(userId: userId, traits: ["plan": "free"])
Herald.shared.setUserToken(userToken)
}On sign-out, call Herald.shared.reset().
4. Track an event
Herald.shared.track("workout_completed", properties: ["minutes": 32, "type": "strength"])Events are queued on the device and sent in batches. Events and attributes lists the rules each call must follow.
5. Register for push
Pass the APNs token to the SDK, ask for permission at a moment that makes sense to the user, and forward notification taps.
extension AppDelegate {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Herald.shared.setPushToken(deviceToken)
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
Herald.shared.handleNotificationResponse(response)
completionHandler()
}
}
struct EnablePushButton: View {
var body: some View {
Button("Turn on workout reminders") {
Task { _ = await Herald.shared.requestPushAuthorization() }
}
}
}requestPushAuthorization() shows the system prompt, registers with APNs when the user allows it, and records the push subscription. iOS push setup covers the APNs key, foreground display and later launches.
6. Show content cards
ContentCardFeed from HeraldUI shows the signed-in user's cards, pinned first and then newest, and logs impressions, clicks and dismissals for you.
struct HomeView: View {
var body: some View {
NavigationStack {
ContentCardFeed()
.navigationTitle("For you")
}
}
}To draw cards in your own views instead, see Building a custom UI.
Verify it works
- Run the app, sign in and log a workout. Send the app to the background: the SDK sends its queue as the app leaves the foreground.
- In the Xcode console, filter for the subsystem
com.herald.sdk. A line that starts withHerald rejected a batchmeans the request failed; anything else at debug level is normal traffic. - In Herald, open Audience > Search users and look up the External ID. The profile shows the traits you passed to
identify, such asplan. - Have an agent send a content card to that user through the same connection. The card appears at the next session start, or right away if you call
Herald.shared.refreshContentCards().
Troubleshooting
- One
Message sync needs a user token; waiting for setUserTokendebug line right after sign-in. With verification Required,identifyfetches messages before the token is set. It is harmless:setUserTokenfetches again. CallsetUserTokenimmediately afteridentify. A session-start in-app message can first show in the user's next session. AMessage sync failed with HTTP 401: Herald refused the user tokenwarning is different: the token the app sent is wrong. See Error codes. Herald rejected the app key: check the publishable key in configure. The app key is wrong, or the connection is not active. The SDK keeps the events and stops sending until the app launches again; fix the key inconfigure.Herald needs a user token: call setUserToken. Identity verification is Required and the signed-in user's token is missing or wrong. The SDK keeps that user's events and sends them after the nextsetUserToken.- The profile does not show the traits. With verification set to Optional, a batch without a token is stored as anonymous and writes nothing to the profile. Call
setUserTokenafteridentify. track ignored: name must not be emptyor a similar line. The SDK checks every call against the server's limits and drops invalid calls on the device. Fix the call; nothing was sent.- No cards. Cards are fetched for identified users only. An agent send made before the user's device first reached Herald is suppressed, so send again after the app has run once.