How to add button to custom notification and respond to the button accordingly?
I'm using UNNotificationContentExtension
and trying to figure out how to add button inside my view and have a IBAction for that button in my extension class?
Please see attachment image:
As you can see I have added two buttons to the UNNotificationContentExtension
class but the never get called?
This is how I set up notification in my app delegate:
func application(_ 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
}
I don't want to add these to UNNotificationAction
like this way :
let ok = UNNotificationAction(identifier: "OKIdentifier",
title: "Turn off", options: [.destructive])
I need to have the buttons inside the view and react to them accordingly. I appreciate if any one can help me with that.
链接地址: http://www.djcxy.com/p/34878.html上一篇: 如何在一个应用程序中迁移多个领域文件