Rich notifications setup
iOS 10 introduced support for rich notifications: they can now contain custom content, such as images, videos, sounds or even a fully custom view controller.
Batch comes with built-in support for these, but due to the way they're implemented, integration of a supplementary SDK is required.
Don't worry, we've made it really easy.
Note: This tutorial assumes that you haven't already added a Notification Content extension. If you do, jump straight to Integrating the Batch Extension SDK.
In order to set up the Batch Extension SDK, you'll need a notification service extension. It's a standard iOS component that will take care of downloading rich content and add it to the notification.
Open your Xcode project, click on the
File menu and then pick
New -> Target. Then, pick
Notification Service Extension and fill in what's left of the wizard. You can name the extension as you wish: we will name it
RichNotificationsExtension for the rest of this tutorial.
Xcode will then ask you if you want to activate the scheme. Press
Before going any further, you might want to check the extension's Deployment Traget. It usually is the latest iOS minor, meaning that your extension will not run on older iOS versions.
We recommend that you set it to the lowest version of iOS that your app supports, but not lower than iOS 10.0 as this is the version that introduced this extension kind.
Install the Batch Extension with the package manager of your choice.
Make sure you're setting the dependency on the extension target. If your Podfile existed before you created your extension, you might need to add it.
... target 'RichNotificationsExtension' do pod 'BatchExtension-ObjC' end
If you don't have your own code, you've probably noticed that Xcode added some sample code for you:
In order to have Batch automatically adding rich content to your notifications, simply replace this code with:
// NotificationService.h -- #import <BatchExtension-ObjC/BAENotificationServiceExtension.h> @interface NotificationService : BAENotificationServiceExtension @end // NotificationService.m #import "NotificationService.h" @implementation NotificationService @end
That's it, no code to write! Start your app, and try sending a rich push from the dashboard.
If you've already added your own extension code, you might want to manually integrate Batch and perform your own modifications to the notification content. In this case, please follow the iOS native documentation.