Survey notifications
These are optional implementations for Sense360 SDK survey notifications.
Notification handlers
All notifications from Sense360 are sent with a UNNotificationCategory of sense360
, handled by the delegate methods below. The iOS SDK calls the completion handlers for all notifications with the sense360
category.
These methods return true
if it was a Sense360 notification and the completion handler was invoked. Ignore notifications where isSense360Notification = true
.
import UIKit
import SenseQuinoaLib
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let _ = Sense360.restore(sendNotifications: true)
UNUserNotificationCenter.current().delegate = self
return true
}
// Follows the rest of the AppDelegate
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// If isSense360Notification = true, Sense360 handles the notification, calls the withCompletionHandler, and your application can skip processing the notification.
let _ = Sense360.userNotificationCenterDidReceive(center: center, didReceive: response, withCompletionHandler: completionHandler)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// If isSense360Notification = true, Sense360 handles the notification, calls the withCompletionHandler, and your application can skip processing the notification.
let _ = Sense360.userNotificationCenterWillPresent(center: center, willPresent: notification, withCompletionHandler: completionHandler)
//Follows the rest of the didReceiveLocalNotification code.
}
}
Notification callbacks
Notification callbacks notify you when a notification is sent, clicked, or cancelled (that is, swiped).
Create the class NotificationHandler.swift
to implement the SenseNotificationDelegate
protocol.
import SenseQuinoaLib
class NotificationHandler: SenseNotificationDelegate {
func notificationClicked(clickData: NotificationClickData){
//Call this method when clicking a notification
print("User was redirected to \(clickData.url.absoluteString)")
}
//Call this method when sending a notification
func notificationSent(){
}
}
Pass NotificationHandler()
into the Sense360 start:sendNotifications:
call.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let handler = NotificationHandler()
// Replace this call to start:sendNotifications: with any previous versions.
Sense360.restore(handler, sendNotifications: true)
}