我想根据 watch 上收到的不同类型的通知设置 watch 应用程序的初始 View Controller 。但我不知道在哪里设置它。
这是 iOS 应用程序的答案 Multiple entry points to a storyboard
最佳答案
watchOS 2
WKExtensionDelegate
相当于应用程序委托(delegate),您可以:
respond to actionable notifications and manage Handoff transitions. You also use the delegate to respond to life-cycle events, such as the activation and deactivation of your app
在 applicationDidFinishLaunching()
中,您可以调用 reloadRootControllersWithNames(_:contexts:)
来指定应用启动时显示的页面集。
您还可以在运行时调用reloadRootControllersWithNames(_:contexts:)
来切换 View Controller 。
watchOS 1
没有等效的应用程序委托(delegate)。
要创建自定义的每个通知 UI,请为通知类别创建一个具有不同名称的新通知界面 Controller 。如果您需要额外的定制,请参阅Managing a Custom Long Look Interface在文档中。具体来说:
When a notification of the correct type arrives, WatchKit chooses your static or dynamic interface based on several factors. WatchKit automatically displays the static interface when a dynamic interface is not available, there is not enough power to warrant displaying the dynamic interface, or you explicitly tell WatchKit not to display the dynamic interface. In all other cases, WatchKit displays your dynamic interface. After making the choice, WatchKit loads the appropriate storyboard resources and prepares the interface as shown in Figure 16-2. The loading process for the dynamic interface is mostly the same as for your app’s other interface controllers, with the exception of processing the notification payload, which is specific to notification interface controllers.
类别名称应与推送通知 JSON 中的 category
字段完全匹配,如本例中的 INVITE_CATEGORY
:
{
"aps" : {
"alert" : "You’re invited!",
"category" : "INVITE_CATEGORY",
}
}
(如果您使用本地通知,而不是推送通知,只需在 UILocalNotification
上设置 category
属性即可。)
Apple Watch 将显示与您的类别对应的通知界面 Controller 。
另请参阅Notification Essentials .
关于appdelegate - Apple Watch 应用程序的应用程序委托(delegate)文件相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28846415/