Rich notifications
Rich notifications are push notifications with images, GIFs, and video. To enable this functionality, you must create a notification service extension—a type of extension that enables modification of a push payload before it is displayed. Refer to Apple’s
UNNotificationAttachment
for a list of supported file types and sizes.
Step 1: Creating a service extension
To create a notification service extension, navigate to File > New > Target in Xcode and select Notification Service Extension.
Ensure that Embed In Application is set to embed the extension in your application.
Step 2: Setting up the notification service extension
A notification service extension is its own binary that is bundled with your app. It must be set up in the Apple Developer Portal with its own app ID and provisioning profile.
The notification service extension’s bundle ID must be distinct from your main app target’s bundle ID. For example, if your app’s bundle ID is com.company.appname
, you can use com.company.appname.AppNameServiceExtension
for your service extension.
Step 3: Integrating rich push notifications
For a step-by-step guide on integrating rich push notifications with BrazeNotificationService
, refer to our tutorial.
To see a sample, refer to the usage in NotificationService
of our Examples app.
Adding the rich push framework to your app
After following the Swift Package Manager integration guide, add BrazeNotificationService
to your Notification Service Extension
by doing the following:
-
In Xcode, under frameworks and libraries, select the add icon to add a framework.
-
Select the “BrazeNotificationService” framework.
Add the following to your Podfile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
target 'YourAppTarget' do
pod 'BrazeKit'
pod 'BrazeUI'
pod 'BrazeLocation'
end
target 'YourNotificationServiceExtensionTarget' do
pod 'BrazeNotificationService'
end
# Only include the below if you want to also integrate Push Stories
target 'YourNotificationContentExtensionTarget' do
pod 'BrazePushStory'
end
For instructions to implement Push Stories, see the documentation.
After updating the Podfile, navigate to the directory of your Xcode app project within your terminal and run pod install
.
To add BrazeNotificationService.xcframework
to your Notification Service Extension
, see Manual integration.
Using your own UNNotificationServiceExtension
If you need to use your own UNNotificationServiceExtension, you can instead call brazeHandle
in your didReceive
method.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import BrazeNotificationService
import UserNotifications
class NotificationService: UNNotificationServiceExtension {
override func didReceive(
_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
) {
if brazeHandle(request: request, contentHandler: contentHandler) {
return
}
// Custom handling here
contentHandler(request.content)
}
}
Step 4: Creating a rich notification in your dashboard
Your Marketing team can also create rich notifications from the dashboard. Create a push notification through the push composer and simply attach an image or GIF, or provide a URL that hosts an image, GIF, or video. Note that assets are downloaded on the receipt of push notifications, so you should plan for large, synchronous spikes in requests if you are hosting your content.