Push notifications
Push notifications tell users when you or the AI replies, even after they've closed the app. Tapping one opens the chat. Without push, most replies go unseen, so set this up before you ship.
Before you start
- Your app has the Push Notifications capability. In Xcode, open your target's Signing & Capabilities tab and add it if it's missing.
- You can sign in to the Apple Developer site with a role that can create keys.
- Hollo is already started at launch.
Create an APNs key
On the Apple Developer site, go to Certificates, Identifiers & Profiles → Keys and create a key with Apple Push Notifications service (APNs) enabled. Download the .p8 file and note its Key ID. Apple only lets you download it once, so keep it somewhere safe.
One key works for all your apps on the team, and for both development and production builds.
Upload it to Hollo
In the dashboard, open your app's Push settings and upload the .p8 file with its Key ID, your Team ID and your app's bundle ID. Hollo encrypts the key at rest and never shows it again.
Pass Hollo the device token
Hollo never asks users for notification permission itself. Ask the way you already do, register for remote notifications, then hand Hollo the token.
SwiftUI apps need an app delegate for this. Add one with @UIApplicationDelegateAdaptor:
import SwiftUI
import UserNotifications
import Hollo
@main
struct DriftwoodApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
init() {
Hollo.start(appKey: "app_XXXX")
}
var body: some Scene {
WindowGroup { ContentView() }
}
}
final class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
UNUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()
return true
}
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Hollo.registerPush(deviceToken: deviceToken)
}
}
UIKit apps add the same two methods to their existing AppDelegate.
registerForRemoteNotifications() doesn't show a prompt. It gets a token that can deliver notifications once the user allows them. Calling it at every launch is normal; Apple may give you a new token at any time, and Hollo keeps the latest one.
Open the chat from a notification
When a user taps a Hollo notification, let Hollo open the conversation. handle(notification:) returns true if the notification was Hollo's, so your own notifications still reach your code:
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse
) async {
if Hollo.handle(notification: response) { return }
// Your own notifications here.
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification
) async -> UNNotificationPresentationOptions {
[.banner, .list, .sound]
}
}
Set the notification centre's delegate in didFinishLaunchingWithOptions, as above. If you set it later, taps that launch the app from closed can be missed.
Ask for permission at a good moment
If your app doesn't ask for notifications yet, a natural moment is right after the user sends their first support message, when a reply is clearly useful:
let center = UNUserNotificationCenter.current()
let granted = try await center.requestAuthorization(options: [.alert, .sound, .badge])
Notification wording
In your app's Push settings you can change what the notification says, for example its title. You can also hide message text, so a notification only says that you've replied. Use this if your conversations often include private details.
When push is off
Some users turn notifications off. They'll still see your reply, and the unread badge, the next time they open the app.
Troubleshooting
No notification arrives.
- Check the user allowed notifications in Settings → Your app → Notifications.
- Check the bundle ID in the dashboard matches your app exactly.
- Check
Hollo.registerPush(deviceToken:)runs. Add a breakpoint indidRegisterForRemoteNotificationsWithDeviceToken. - The simulator can receive pushes, but a real device is the most reliable test.
didRegisterForRemoteNotificationsWithDeviceToken is never called. The Push Notifications capability is probably missing, or your provisioning profile doesn't include it. Implement didFailToRegisterForRemoteNotificationsWithError to see Apple's error.
Tapping the notification opens the app but not the chat. Make sure the notification centre's delegate is your app delegate, and that Hollo.handle(notification:) is called before your own handling.