我正在开发一个WatchOS3
应用程序,用户可以在其中接收带有自定义操作的本地通知。用户可以在通知上调用 2 个自定义操作,即选项 1 和选项 2。用户点击任一选项后,应用程序应启动到特定视图。
到目前为止,通知操作已在以下函数中正确处理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()
}
这是我的主要代码InterfaceController
,其中定义了通知类别:
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
}
现在,当点击 option1 或 option2 时,如何告诉我的应用程序启动到特定视图?