通知操作按钮处理可以Extension
在Containing App
.
轻按操作按钮时,手柄首先转到 ,Extension
然后根据Containing App
需要转到 。如果Extension
不处理通知动作,则将句柄传递给containing app.
点击按钮会启动您的应用程序(在前台或后台),并让您有机会执行指定的操作。
扩展处理:
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void)
{
//You need to handle all the actions that appear with notification..
completion(.dismissAndForwardAction)
}
完成闭包采用 UNNotificationContentExtensionResponseOption 类型的值:
enum UNNotificationContentExtensionResponseOption : UInt
{
case doNotDismiss //the custom UI is not dismissed after handling the action
case dismiss //the custom UI is dismissed after handling the action
case dismissAndForwardAction //the custom UI is dismissed after handling the action and the control is then passed to containing app for any additional handling
}
包含应用程序中的处理:
extension AppDelegate : UNUserNotificationCenterDelegate
{
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
// Action handling - handling for all actions is not required
completionHandler()
}
}
有关更多信息,您可以参考此(https://github.com/pgpt10/RichNotificationSample)教程。