什么是苹果手表应用程序的应用程序委托文件?

What's the equivalent of app delegate file for apple watch app?

我想根据手表上收到的不同类型的通知设置手表应用程序的初始视图控制器。但是不知道在哪里设置。

这是 iOS 应用的答案 Multiple entry points to a storyboard

watchOS 2

WKExtensionDelegate相当于app 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:)来切换视图控制器。

watchOS 1

没有等效的应用程序委托。

要创建自定义的每个通知 UI,请为通知类别创建一个具有不同名称的新通知接口控制器。如果您需要额外的自定义,请参阅文档中的 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.

类别名称应与推送通知中的 category 字段完全匹配 JSON,如本例中的 INVITE_CATEGORY

{
    "aps" :  {
        "alert" : "You’re invited!",
        "category" : "INVITE_CATEGORY",
    }
}

(如果您使用的是 本地 通知,而不是推送通知,只需在 UILocalNotification 上设置 category 属性。)

Apple Watch 将显示与您的类别对应的通知界面控制器。

另见 Notification Essentials

在 WatchKit 2 中有一个扩展委托。

来自watchOS 2 Transition Guide

In watchOS 2, your WatchKit extension has an extension object and corresponding delegate object to manage behavior that is central to your app. The WKExtension object is a shared object that is available whenever your Watch app runs. The extension object has an associated delegate object that conforms to the WKExtensionDelegate protocol.