The tutorial really should have gone to the trouble, and made code available, for handling action buttons.
Here’s how to handle the action buttons reponse in LocalNotifications.swift
extension LocalNotifications: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification
) async → UNNotificationPresentationOptions {
print(“willPresent fired from watch delegate”)
UNUserNotificationCenter.current().delegate = self
let category = notification.request.content.categoryIdentifier
// Notification received, display to user, even if app is in foreground or background
return [.banner, .badge, .list, .sound]
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () → Void) {
NSLog(“(#function)”)
print(“didReceive fired from watch delegate”)
let r = response
switch response.actionIdentifier {
case "ACCEPT_CALL_ACTION":
print("Clicked ACCEPT_CALL_ACTION, sendMessageToFlutter")
break
case "DECLINE_CALL_ACTION":
print("Clicked DECLINE_CALL_ACTION")
break
// Handle other actions…
default:
break
}
completionHandler()
}
}