Push Notifications

This article explains how to enable push notifications in Intercom for iOS. If you are new to push notifications in iOS, check out this page first.

To enable Intercom push notifications, you first need to create a private key, upload it to Intercom, and enter details about your app.

Step 1: Create a Private Key

Using these instructions, create and download a private key with APNs enabled. Note the Key ID for the next step.

Alternatively, use an existing private key with APNs enabled.

Step 2: Enable in Intercom

Go to your workspace settings and select Installation > iOS. In the "Enable Push Notifications" section:

  1. Upload the .p8 file you just created
  2. Enter the Key ID from Step 1
  3. Enter the Bundle ID for the app you want to send notifications to
  4. Enter the Apple team ID
  5. Click Save

Adding push credentials for multiple mobile apps

You can configure multiple push credentials if you have more than a single mobile app. To create multiple push credentials, you must have a default push credential already configured.

Click on the + Configure another app to add a new push credential.

Step 3: Register Device Tokens

To enable your users to receive push notifications from Intercom via Intercom for iOS, you must request permission to send push notifications and register the device token of your user in your AppDelegate.

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [Intercom setDeviceToken:deviceToken failure:^(NSError * _Nullable error) {
        // Handle error
    }];
}

If the failure block of the above call is executed, you can check against our list of error codes to help debug the issue.

At this stage you should also make sure that you have enabled the Push Notifications capability in Xcode.

Step 4: Handling Intercom Push Notifications

Automatically (Default)

When your app receives a push notification, Intercom for iOS checks if it is an Intercom push notification and opens the message if required. To do this we safely swizzle the public methods in UIApplicationDelegate that handle receiving push notifications. 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:

  1. Add the following to your Info.plist:
    IntercomAutoIntegratePushNotifications with a value of NO

  1. Handle Intercom push notifications manually in didReceiveNotificationResponse in your UNUserNotificationCenterDelegate:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
    //Add any custom push handling for your own app here
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    if ([Intercom isIntercomPushNotification:userInfo]) {
        [Intercom handleIntercomPushNotification:userInfo];
    }
    completionHandler(UIBackgroundFetchResultNoData);
}

Step 5: Testing Intercom Push Notifications

You can test if push notifications are working properly in your app by sending a manual message to the app user via Intercom.

Badge Values

Intercom never changes the badge value of your app. Thus we can ensure that whatever badge value you're managing in your app, we don't alter in any way.

Troubleshooting

If you are having trouble getting push notifications to work in your app, here's a list of things you should check:

  • Ensure you ticked the box 'Send a push notification' when you send a manual message.
  • Ensure you are requesting permission from your users to send push notifications.
  • Do you get a device token from APNS? If you put a breakpoint into the application:didregisterforremotenotificationswithdevicetoken: delegate call, you should get a token shortly after your app launches.
  • Have you set the correct Bundle ID in Settings > Installation > iOS? Make sure it matches the app that you want push notifications sent to.
  • Is your private key still active? Check your keys to make sure it has not been revoked.
  • You can find more technical information and troubleshooting steps in the Apple iOS Developer Library.

And as always, you can contact us via Intercom. We're always here to help 😀