appdelegate - Apple Watch 应用程序的应用程序委托(delegate)文件相当于什么?

标签 appdelegate watchkit apple-watch

我想根据 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/

相关文章:

ios - iOS Apple App Store 下载链接中的转义参数

ios - 当我从 Scheme Url 启动应用程序时未调用 openUrl

ios - 如何在 Objective C 中将数组数据从 iPhone 传递到 Apple Watch

xcode - 如何避免此错误 : "Took too long to show custom notification. Falling back to static."?

iphone - Apple Watch 应用也需要 iphone 界面吗?

ios - WKInerfaceLabel 放置在 WKInerfaceTable 之上,但不希望它与 WKInterfaceTable 一起滚动

ios - 将 Objective-C AppDelegate 类别类转换为 Swift 类

ios - 只需单击启动图标,应用程序就会卡住我的整个手机

ios - 在 Apple Watch 上实现登录机制的最佳实践

ios - WatchKit 扩展崩溃