首页 > 解决方案 > 从消息过滤器扩展发送本地通知

问题描述

我正在实施消息过滤器扩展,但在使用通知时遇到问题。关键是我想为进入垃圾文件夹的每条消息触发通知。我在 MainViewController 中测试了通知的代码,它工作正常。Bellow 是我正在使用的代码,我在 viewDidLoad() 方法中要求用户权限。

函数发送通知(){

    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)     }

当消息被过滤为垃圾邮件以通知用户时,有没有办法发送通知?谢谢开发者。

标签: iosswiftsmsios-extensions

解决方案


推荐阅读