Push Notifications

Requirements


Configure handling Push Notifications in your application. See Apple Developer - Notifications.

Configuring Firebase


Google Firebase Cloud Messaging is necessary to handle Mobile Campaigns sent from Synerise.

  1. Follow the instructions in Firebase - Get Started on iOS.
  2. Integrate the Firebase with Synerise. See Integration section.

Setting up Firebase Cloud Messaging for Synerise SDK

Extend the Firebase Messaging Delegate so our SDK can receive the Firebase token that is required to deliver Push Notifications from Synerise:

   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
   	FirebaseApp.configure()
   	Messaging.messaging().delegate = self

   	if #available(iOS 10, *) {
   		UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in

   		}
   	} else {
   		let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
   		application.registerUserNotificationSettings(settings)
   	}

   	application.registerForRemoteNotifications()
   }

   // MARK: - MessagingDelegate

   func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
   	Client.registerForPush(registrationToken: fcmToken, success: { (success) in
   		// success
   	}) { (error) in
   		// failure
   	}
   }

Make sure that the Firebase token is always up-to-date by implementing a suitable method from the SNRSyneriseDelegate (see the Synerise Delegate section):

   // MARK: - SyneriseDelegate

   func snr_registerForPushNotificationsIsNeeded() -> Void {
   	guard let fcmToken = Messaging.messaging().fcmToken else {
   		return
   	}

   	Client.registerForPush(registrationToken: fcmToken, success: { (success) in
   		// success
   	}) { (error) in
   		// failure
   	}
   }

Supporting Rich Media in Push Notifications


To add this feature in your Simple Push Campaigns, you must:

  1. Configure the App Group that identifies the group used by applications the and extensions it belongs to.
    Documentation on configuring App Groups is available at Apple Developer - App Groups.
  2. Add the Notification Content Extension in your iOS project - separately for each type of our Rich Media extensions.
  3. Configure your application and the SDK.

Notification Content Extension implementation

Synerise SDK does most of the work needed and provides classes for the Notification Content Extensions. When you create an extension, you only need to make it inherited from a suitable Synerise SDK class.

See the examples Notification Content Extensions with correct configuration:

import UIKit
import UserNotifications
import UserNotificationsUI
import SyneriseSDK

class NotificationViewController: SingleMediaContentExtensionViewController, UNNotificationContentExtension {

    func didReceive(_ notification: UNNotification) {
        Synerise.settings.notifications.appGroupIdentifier = "YOUR_APP_GROUP_IDENTIFIER"
        setSyneriseNotification(notification)
    }

    func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
        setSyneriseNotificationResponse(response, completionHandler: completion)
    }
}
Note: Remember about correct configuration in your extension's \*.plist file. See Notification Content Extensions in the Sample Swift App.

Host Application implementation

When the extension is configured, pass your app group identifier to the SDK (Set up App Group Identifier) and add custom categories in your application.

You have to create notifications categories with the right identifiers. The identifiers must be taken from the Synerise SDK constants. This does not affect button names.

Synerise.settings.notifications.appGroupIdentifier = "YOUR_APP_GROUP_IDENTIFIER"

let singleMediaCategory = UNNotificationCategory(identifier: SNRSingleMediaContentExtensionViewControllerCategoryIdentifier, actions: [], intentIdentifiers: [], options: [])

let carouselPrevious = UNNotificationAction(identifier: SNRCarouselContentExtensionViewControllerPreviousItemIdentifier, title: "Previous", options: [])
let carouselAction = UNNotificationAction(identifier: SNRCarouselContentExtensionViewControllerChooseItemIdentifier, title: "Go!", options: UNNotificationActionOptions.foreground)

let carouselNext = UNNotificationAction(identifier: SNRCarouselContentExtensionViewControllerNextItemIdentifier, title: "Next", options: [])

let carouselCategory = UNNotificationCategory(identifier: SNRCarouselContentExtensionViewControllerCategoryIdentifier, actions: [carouselPrevious, carouselAction, carouselNext], intentIdentifiers: [], options: [])

UNUserNotificationCenter.current().setNotificationCategories([singleMediaCategory, carouselCategory])

Handling incoming Synerise Push Notifications


Note: You may disable handling Push Notifications in the SDK at any time. See Enable/disable notifications.

Documentation on how to prepare Push Notifications on app.synerise.com is available in our Mobile Knowledge Base.

In order to handle Synerise Push Notifications, you must pass the incoming push payload to the Synerise SDK.

The following code shows how to handle Push Notifications and Silent Push Notifications in the AppDelegate:

// iOS 9
// Push Notifications
// Silent Push Notifications

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
	let isSyneriseNotification: Bool = Synerise.isSyneriseNotification(userInfo)
	
	if isSyneriseNotification {
		Synerise.handleNotification(userInfo)
	}
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
	let isSyneriseNotification: Bool = Synerise.isSyneriseNotification(userInfo)
	
	if isSyneriseNotification {
		Synerise.handleNotification(userInfo)
		completionHandler(.noData)
	}
}

func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
	let isSyneriseNotification: Bool = Synerise.isSyneriseNotification(userInfo)
	
	if isSyneriseNotification {
		Synerise.handleNotification(userInfo)
		completionHandler()
	}
}

// iOS 10 and above
// Push Notifications

// MARK: - UNUserNotificationCenterDelegate

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
	let userInfo = response.notification.request.content.userInfo
	
	let isSyneriseNotification: Bool = Synerise.isSyneriseNotification(userInfo)
	
	if isSyneriseNotification {
		Synerise.handleNotification(userInfo)
		completionHandler()
	}
}

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
	let userInfo = notification.request.content.userInfo

	let isSyneriseNotification: Bool = Synerise.isSyneriseNotification(userInfo)
	
	if isSyneriseNotification {
		Synerise.handleNotification(userInfo)
		completionHandler(UNNotificationPresentationOptions.init(rawValue: 0))
	}
}
Important: All of these methods must be implemented to ensure proper handling of Push Notifications.
😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.