Send local notification from Message Filter Extension

Hello guys,

I'm implementing a message filter extension and I have an issue using notifications. The point is that I would like to trigger a notification for every message that comes into the junk folder. I tested the code for the notification in the MainViewController and it's working fine. Bellow is the code I'm using and I asked for user permissions in viewDidLoad() method.

  func sendNotification(){

        print("sendNotification.....")

        //creating the notification content

        let content = UNMutableNotificationContent()

        //adding title, subtitle, body and badge

        content.title = "Hey, test notification"

        content.subtitle = "iOS Development is good"

        content.body = "We are learning about iOS Local Notification"

        content.badge = 1

        //getting the notification trigger

        //it will be called after 5 seconds

        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)

        //getting the notification request

        let request = UNNotificationRequest(identifier: "SimplifiedIOSNotification", content: content, trigger: trigger)

        UNUserNotificationCenter.current().delegate = self

        //adding the notification to notification center         UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)     }

Is there a way of sending the notification when a message is filtered as junk to inform the user about that?

Thank you devs.

Send local notification from Message Filter Extension
 
 
Q