Before you begin
- Delivery — Delivery must be enabled in your workspace.
- Parent model — Delivery must have a parent model selected in the Data source card on Delivery > Settings > Profiles. Push notifications are addressed to users by its primary key.
- Apple Developer access — You need the Account Holder or Admin role to create an APNs key.
- Physical device — The iOS Simulator can’t receive push notifications. Test on a device running a debug build from Xcode or a TestFlight build.
- iOS 13 or later — The SDK supports iOS 13.0 and later.
Collect your Apple credentials
Hightouch sends notifications through Apple Push Notification service (APNs) on your behalf, using four values from your Apple Developer account.
Apple lets you download a
.p8 file only once, when you create the key. One key works for every app on your team, so check whether your team already has one before you create another.
Create an iOS event source
The SDK sends device registrations and notification opens to a Hightouch event source of type iOS. Skip this section if your workspace already has one.- Go to Event Collection > Event sources and click Create source.
- Click iOS and finish creating the source.
- On the source’s Setup tab, copy the Write key and the API Host.
Register your app in Hightouch
- Go to Delivery > Settings > Apps. If you already registered this app for Android, open it and skip to the next step. Otherwise, click Add, enter a Name, and click Add. The name appears on every notification.
- On the iOS (APNs) card, click Enable.
- Enter your Apple credentials, then save.
- Copy the App ID from the top of the iOS (APNs) card.
The App ID isn’t your app’s package name or bundle ID. It’s an ID that Hightouch assigns.
Match the APNs environment to your build
Apple runs separate push environments for development and production, and a device receives pushes only from the environment its build was signed for.
Apps use Production by default. To test a debug build from Xcode, ask your Hightouch team to switch your app to Development, and to switch it back when you move to TestFlight. After each switch, call
identify again on your test device.
Configure your Xcode project
Add capabilities
On your app target’s Signing & Capabilities tab, add these capabilities:- Push Notifications
- Background Modes, with Remote notifications selected
Install the SDK
Addhttps://github.com/ht-sdks/events-sdk-swift with Swift Package Manager, and add both the Hightouch and HightouchPush libraries to your app target. In Xcode, go to File > Add Package Dependencies.
If you manage dependencies in Package.swift, add the package and both libraries:
Add a Notification Service Extension
A Notification Service Extension lets notifications show images and action buttons. Without one, notifications still arrive as plain text.- Go to File > New > Target and select Notification Service Extension.
- Add the
HightouchPushlibrary to the new target. - Replace the generated
NotificationService.swiftwith the Hightouch base class:
Initialize the SDK
InitializeHightouchPush in application(_:didFinishLaunchingWithOptions:) with your write key, API host, and App ID. Set the notification center delegate in the same place so the app doesn’t miss a tap that launches it.
YOUR_API_HOST with the API Host from your event source’s Setup tab, such as eu-west-1.hightouch-events.com, and keep /v1 at the end.
If you already use the iOS SDK to track events, pass your existing instance with HightouchPush.initialize(analytics: analytics, config: ...) instead. Its write key must belong to your iOS event source.
In a SwiftUI app, attach the app delegate with @UIApplicationDelegateAdaptor(AppDelegate.self). For a complete app delegate, see the PushTestApp sample in the SDK repository.
HightouchPushConfig takes these options:
Register the device for push
Ask the user for permission, register with APNs, and pass the device token to the SDK. You decide when to ask; many apps wait until after onboarding. Request permission and register:Identify users on login and logout
Callidentify when a user logs in and logout when they log out:
identify links the device to that user, and logout unlinks it so the device stops receiving their notifications.
If you also track events with the iOS SDK, call HightouchPush.identify instead of analytics.identify so the device stays linked to the right user.
Handle notification taps
Forward notification taps to the SDK, which records the open and follows the notification’s link:userInfo contains a hightouch key.
iOS hides notifications that arrive while your app is open. To show them, implement willPresent:
Handle deep links
By default, the SDK openshttps links as Universal Links when they match your app’s Associated Domains, and in the default browser otherwise. To route links yourself, set a urlDelegate and return true for links you handle:
myapp://, add the scheme to allowedProtocols.
Receive silent pushes
A silent push wakes your app in the background without showing a notification, and delivers custom data to yoursilentPushDelegate. Silent pushes need the Remote notifications background mode.
Forward background notifications to the SDK:
initialize:
await HightouchPush.setBadge(3) or await HightouchPush.resetBadge().
Send yourself a test push
Run your app on a device and log in so thatidentify runs, then send a test from Hightouch. In both places, Validate checks that a device is registered for the user ID you enter.
From app settings: Go to Delivery > Settings > Apps, open your app, and click Test. Enter your user ID, click Validate, then click Send test. The test includes an image, so it also checks your Notification Service Extension.
From the campaign editor: Go to Delivery > Campaigns, click Add campaign, and select Push. In the Create a new campaign dialog, select your app under Choose apps to target, choose a brand if asked, and click Continue. Under Content, click Edit and write your message. On the Preview tab, click Send test, enter your user ID, click Validate, then click Send test.
If Validate finds no device, you can enter a device token instead. A test that arrives this way means your push credentials work and the device isn’t linked to that user.
Troubleshooting
No active devices found
Validate shows this when no device is registered for the user ID. Check that:appIdis the App ID from your app’s iOS (APNs) card.- Your app calls
identifyafter the user logs in, with the parent model’s primary key. - The API host in your SDK setup matches the API Host on your iOS event source’s Setup tab.
identify again on the device. To see what your app sends, open your iOS event source’s Debugger tab. After identify, you see a CEP Push Token Events event with your user ID and an app_id that matches your App ID.
Validate passes, but no notification arrives
Your app’s APNs environment doesn’t match your build. See Match the APNs environment to your build.No ios event source found for this workspace
You see this when you enable the iOS (APNs) card before your workspace has an iOS event source. Create an iOS event source, then click Enable again. If your workspace has more than one iOS event source, contact Hightouch support.Notifications arrive without images or buttons
Check that your project has a Notification Service Extension and that the extension target linksHightouchPush.
Next steps
- Preview and test to render a message against real profiles before you send it.
- Send a campaign to schedule your first push to an audience.