【发布时间】:2016-10-14 17:50:36
【问题描述】:
我正在开发一个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 时,如何告诉我的应用程序启动到特定视图?
【问题讨论】:
标签: watchkit watchos-3 wkinterfacecontroller usernotifications