I'm developing a WatchOS3
application in which the user receives local notifications with custom actions. The user has 2 custom actions that he can call on the notification, option 1 and option 2. After the user taps on either of the options, the app should launch into a specific view.
So far, the notification actions are handled correctly with this function in the ExtenionsDelegate
:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Tapped in notification")
let identifier = response.actionIdentifier
print(identifier)
switch(identifier){
case "option1":
print("tapped option1")
case "option2":
print("tapped option2")
default: break
}
completionHandler()
}
And here's the code from my main InterfaceController
in which the notifications categories are defined:
func actioncategories() {
let option1 = UNNotificationAction(identifier: "option1", title: "Test Option 1", options: .foreground) //Button 1
let option2 = UNNotificationAction(identifier: "option2", title: "Test Option 2", options: .foreground) //Button 2
let actioncategory = UNNotificationCategory(identifier: "action_category", actions: [option1, option2], intentIdentifiers: [])
UNUserNotificationCenter.current().setNotificationCategories([actioncategory]) //setting actions & categories
}
Now how do I tell my application to launch into a specific view when either option1 or option2 is tapped?