Messages
In-app messaging and push notifications with the Grovs iOS SDK
If console messages have automatic display enabled in your dashboard, they will appear in your app without any additional integration.
Push notifications
Follow the steps below to enable push notifications for messages sent from the Grovs dashboard.
1. Add the Push Notifications capability
In Xcode:
- Select your app target
- Go to Signing & Capabilities
- Click + Capability
- Search for and add Push Notifications
You also need to add the Background Modes capability and check Remote notifications if you want your app to receive silent or background pushes.
2. Upload your APNs key to Grovs
In your Apple Developer account:
- Go to Keys and create a new key with Apple Push Notifications service (APNs) enabled
- Download the
.p8key file and note the Key ID and your Team ID
Then in the Grovs dashboard:
- Go to your app's Settings → Push Notifications
- Upload the
.p8key file - Enter the Key ID and Team ID
3. Request notification permission
Before your app can receive push notifications, you must ask the user for permission. Add this early in your app's lifecycle — for example, in application(_:didFinishLaunchingWithOptions:) or when contextually appropriate:
import UserNotifications
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}Call
registerForRemoteNotifications()on the main thread after the user grants permission. This triggers the system to request a device token from APNs.
4. Pass the device token to Grovs
Implement the AppDelegate callback to receive the token and forward it to the SDK:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
Grovs.pushToken = token
}You can also handle registration failures for debugging purposes:
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Push registration failed: \(error.localizedDescription)")
}Push notifications do not work in the iOS Simulator. Test on a physical device.
Displaying messages
Show the full list of messages as a modal:
Grovs.displayMessagesViewController {
// Modal was dismissed
}Unread count
Get the number of unread messages — useful for showing a badge:
Grovs.numberOfUnreadMessages { count in
print("Unread: \(count)")
}