Step 1

Making the environment suitable for Notification. Make sure you enabled Background Modes and Push Notification

https://i.stack.imgur.com/Y6JlQ.png

https://i.stack.imgur.com/6pvyj.png

Step 2: Creating an UNNotificationContentExtension

Click on the + icon in the bottom which creates a target template and select Notification Content Extention -> next -> create a name for the content extension -> finish

https://i.stack.imgur.com/bpCjg.png

Step 3:Configuring the info.plist file of the created extension

https://i.stack.imgur.com/CDSun.png

The dictionary in NSExtension signifies how the notification content is displayed, these are performed on long pressing the received notification

Step 4: Creating UNNotificationAction and UNNotificationCategory in our application

In your app’s AppDelegate.swift didFinishLaunchingWithOptions function add

let userNotificationAction:UNNotificationAction = UNNotificationAction.init(identifier: "ID1", title: "வணக்கம்", options: .destructive)
  let userNotificationAction2:UNNotificationAction = UNNotificationAction.init(identifier: "ID2", title: "Success", options: .destructive)
  
  let notifCategory:UNNotificationCategory = UNNotificationCategory.init(identifier: "CATID1", actions: [userNotificationAction,userNotificationAction2], intentIdentifiers: ["ID1","ID2"] , options:.customDismissAction)
  
  UNUserNotificationCenter.current().delegate = self
  UNUserNotificationCenter.current().setNotificationCategories([notifCategory])
  UIApplication.shared.registerForRemoteNotifications()

We created two UNNotificationAction with identifiers ID1 and ID2 and added those actions to a UNNotificationCategory with identifier CATID1 (the categoryID in ContentExtension’s info.plist file are same, what we created here should be used in payload and the plist file). We set the category to our application’s UNUserNotificationCenter and in next line we are registering for the notification which calls the didRegisterForRemoteNotificationsWithDeviceToken function where we get the device token

Note: dont forget to import UserNotifications in your AppDelegate.swift and add UNUserNotificationCenterDelegate

Step 5: Sample payload for the NotificationContent