Push Notifications

Requirements

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

Configuring Firebase

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

  1. Follow the instructions in this article.
  2. Integrate the Firebase project with Synerise. See this article.

Setting up Firebase Cloud Messaging for Synerise

  1. 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
       	}
       }
       
  2. To make sure that the Firebase token is always up-to-date, implement the snr_registerForPushNotificationsIsNeeded() method from the Synerise Delegate (Synerise Delegate):
       // 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
       	}
       }
    
       

Handling incoming Synerise Push Notifications

Documentation on how to prepare push notifications on app.synerise.com is available in our 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:

Important: All of these methods must be implemented to ensure proper handling of notifications.
// 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))
	}
}
Note: You may disable handling Push Notifications in the SDK at any time. See Enable/disable notifications.

Synerise Push Notification payload structure

Each notification follows this basic structure:

{
    "aps": {
        ...
    },    
    "issuer": "Synerise",
    "message-type": "dynamic-content",
    "content-type": "template-banner",
    "content": {

    }
}
  • issuer - in Synerise notifications, the issuer is always Synerise.
  • message-type - specifies if the content is static or dynamic.
  • content-type - specifies the type of content in the payload.
  • content - the actual content (for example, in HTML).

Methods such as Synerise.isNotificationSimplePush(_:) let you check if the incoming content is of the expected type.

For more information, see the method reference.

😕

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.