iOS Notification Handling

iOS does differentiate between the action which happens when pressing the notification and the quick actions which are presented to the user when long pressing a notification.

Firebase Cloud Messaging

To integrate MOOST Notifications into your iOS Application you can use Firebase Cloud Messaging (FCM). With FCM you have a centralized tool to send notifications to your End-users either to Android or iOS Apps. For more information on how to setup Firebase for iOS you can consult this documentation.

Handling FCM notifications

func userNotificationCenter(_ center: UNUserNotificationCenter,
       didReceive response: UNNotificationResponse,
       withCompletionHandler completionHandler: 
         @escaping () -> Void) {
       
   // Get the additional information from the original notification.
   let userInfo = response.notification.request.content.actions
   let url = userInfo["parameter"]["en"] as! String
        
   // Perform the task associated with the action.
   switch response.actionIdentifier {
    case "OPENAPP":
        sharedAppManager.openApp()
        break
    case "STOPDELIVERY":
        sharedAppManager.sendStopDelivery()
        break
    case "OPENWEB":
        sharedAppManager.openWeb(url)
        break
    default:
        sharedAppManager.openApp(url)
        break
   }
    
   // Always call the completion handler when done.    
   completionHandler()
}

Last updated

© 2023 MOOST AG