Rich Push Notifications
With Intercom version 12.3.0+, you can send rich push notifications on iOS. You can add images to your notifications.
Prerequisites
Before you begin with this, make sure you have gone through Push Notifications. Everything required for simple push notifications needs to be done in order for Rich Push Notifications to work.
Once you are finished with setting up basic push notifications, you can proceed further.
Step 1: Create Notification Service Extension
In Xcode, go to File -> New -> Target, and choose “Notification Service Extension”. Give it a name and click finish. A new target will be added to your project. Set the desired deployment target. The extension will also require its own provisioning profile.
Step 2: Integrate Intercom
In your podfile, add a new target for your Notification Service Extension and add the Intercom pod to that target. Run pod install
to install the pod to the extension.
target :YourNotificationServiceExtensionTargetName do pod 'Intercom' End
Step 3: Handling Intercom Push Notifications
Automatically (Default)
When your NotificationServiceExtension receives a push notification request, Intercom for iOS checks if it is an Intercom push notification and if it is, it then downloads the media and attaches it to the notification. To do this we safely swizzle the public methods in your Notification Service Extension’s "Principal Class", which will be NotificationService
by default, that handle receiving push notification requests. We do not use any private APIs to do this.
Manually
In certain circumstances you may want more control of your push notifications. You can disable automatic handling of Intercom push notifications by doing the following:
- Add the following to your
Info.plist
of your Notification Service Extension:IntercomAutoIntegratePushNotifications
with a value ofNO
.
Import Intercom in your NotificationService class.
Handle Intercom push notifications manually in
didReceiveNotificationResponse
in yourUNNotificationServiceExtension
:
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; if (!self.bestAttemptContent) { contentHandler(request.content); return; } if ([Intercom isIntercomPushNotification:self.bestAttemptContent.userInfo]) { [Intercom handleIntercomRichPushNotificationContent:self.bestAttemptContent withContentHandler:contentHandler]; } else { // Handle non Intercom push notifications here. self.contentHandler(self.bestAttemptContent); } }