如何将按钮添加到自定义通知并相应地响应按钮?

我正在使用UNNotificationContentExtension并试图弄清楚如何在我的视图中添加按钮,并在我的扩展类中为该按钮设置IBAction?

请参阅附件图片:

在这里输入图像描述

正如你所看到的,我已经向UNNotificationContentExtension类添加了两个按钮,但永远不会被调用?

这是我在我的应用程序委托中设置通知的方式:

func应用程序(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?) - > Bool {

let center = UNUserNotificationCenter.current()
let options: UNAuthorizationOptions = [.alert]

center.requestAuthorization(options: options) { (authorized, error) in
    if authorized {
        let categoryId = "com.tutplus.Custom-Notification-Interface.notification"

        let category = UNNotificationCategory(identifier: categoryId, actions: [], intentIdentifiers: [], options: [])
        center.setNotificationCategories([category])

        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 30, repeats: false)
        let content = UNMutableNotificationContent()
        content.categoryIdentifier = categoryId
        content.title = "Notification Title"
        content.subtitle = "Notification Subtitle"
        content.body = "Notification body text"
        content.userInfo = ["customNumber": 100]

        let request = UNNotificationRequest(identifier: "exampleNotification", content: content, trigger: trigger)
        center.add(request, withCompletionHandler: nil)
    }
}

return true

}

我不想像这样将这些添加到UNNotificationAction

let ok = UNNotificationAction(identifier: "OKIdentifier",
                              title: "Turn off", options: [.destructive])

我需要在视图内部有按钮并相应地对它们做出反应。 我很感激,如果有人能帮助我。

链接地址: http://www.djcxy.com/p/34877.html

上一篇: How to add button to custom notification and respond to the button accordingly?

下一篇: RequestAuthorization for push outside the didFinishLaunchingWithOptions