Push Notifications

Push Notifications

As described in our Setup Your App with Locally article, because Locally uses AWS SNS (Simple Notification Service) for Push Notifications, to use Push Notifications in your application, you will need to provide:

  • a .p12 Certificate and it’s Password (iOS)
    and/or
  • a Firebase Cloud Messaging Key (Android)

Android Applications

To enable push notifications to your device, you will need to provide your Firebase token as shown below. When successful, this function provides a response of true. Otherwise, the response is false.


private fun enablePushNotifications(){
            EngageSDK.enablePushNotifications("YOUR FIREBASE TOKEN") { //here you can handle the response
                if(it) System.out.println("Push notifications enabled")
                else System.out.println("Push notification error")
            }
        }

iOS Applications

Registering for Push Notifications

To register for Push Notifications:

  1. Implement the delegate method didRegisterForRemoteNotificationsWithDeviceToken on your AppDelegate
  2. Set the device token:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
	Engage.deviceToken = deviceToken
}

Setting up Push Notification Preview Display

Setting up your app to display Push Notification Previews requires two steps:

Adding A Notification Service Extension to Your Project

Follow these two steps:

  • Add a Target by going to File/New/Target…

  • On the iOS tab, choose Notification Service Extension as the template for your new target

Calling the RemoteNotificationPreviewDisplayer

To change your NotificationService to call RemoteNotificationPreviewDisplayer, add the following:

import LocallyEngageSDK
import UserNotifications
import UserNotificationsUI

class NotificationService: UNNotificationServiceExtension {

	override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
		RemoteNotificationPreviewDisplayer.displayPreview(withNotificationRequest: request, andHandler: contentHandler)
	}
}

Configuring Your Plist File

For Push Notifications to work properly, you must make the following modifications to your Plist file:

  • Remove the NSExtensionMainStoryboard key
  • Set the other NSExtension keys as shown in the  image below

Configuring the Notification View Controller

To Configure the Notification View Controller:

  1. Remove your MainInterface.storyboard file
  2. Change your NotificationViewController to call RemoteNotificationViewController on your viewDidLoad method:
import LocallyEngageSDK

class NotificationViewController: UIViewController {

	override func viewDidLoad() {
		super.viewDidLoad()
		_ = RemoteNotificationViewController()
	}
}