苹果手表应用程序的应用程序委托文件相当于什么? [英] What's the equivalent of app delegate file for apple watch app?

查看:30
本文介绍了苹果手表应用程序的应用程序委托文件相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to set the initial view controller for the watch app base on different type of notification received on the watch. But I don't know where's to set it.

这是 iOS 应用的答案故事板的多个入口点

This is the answer for an iOS app Multiple entry points to a storyboard

推荐答案

watchOS 2

WKExtensionDelegate 相当于应用程序委托,您可以:

watchOS 2

WKExtensionDelegate is the equivalent of the app delegate, where you can:

响应可操作的通知并管理 Handoff 转换.您还可以使用委托来响应生命周期事件,例如应用的激活和停用

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:)来指定应用启动时显示的页面集.

In applicationDidFinishLaunching(), you can call reloadRootControllersWithNames(_:contexts:) to specify the set of pages displayed when your app launches.

您也可以在运行时调用 reloadRootControllersWithNames(_:contexts:) 来切换视图控制器.

You can also call reloadRootControllersWithNames(_:contexts:) at runtime to switch view controllers.

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

There's no app delegate equivalent.

要创建自定义的每个通知 UI,请为通知类别创建一个具有不同名称的新通知界面控制器.如果您需要其他自定义,请参阅管理自定义长查看文档中的界面.具体:

To create a custom per-notification UI, create a new Notification Interface Controller with a distinct name for the Notification Category. If you need additional customization, see Managing a Custom Long Look Interface in the docs. Specifically:

当收到正确类型的通知时,WatchKit 会根据多种因素选择您的静态或动态界面.当动态界面不可用时,WatchKit 会自动显示静态界面,没有足够的能力保证显示动态界面,或者您明确告诉 WatchKit 不显示动态界面.在所有其他情况下,WatchKit 会显示您的动态界面.做出选择后,WatchKit 会加载相应的storyboard 资源,并准备好如图16-2 所示的界面.动态界面的加载过程与您应用的其他界面控制器的加载过程大致相同,但处理通知负载(特定于通知界面控制器)除外.

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:

The category name should exactly match the category field in your push notification JSON, like INVITE_CATEGORY in this example:

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

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

(If you're using local notifications, not push notifications, just set the category property on your UILocalNotification.)

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

Apple Watch will display the notification interface controller corresponding to your category.

另见 通知要点.

这篇关于苹果手表应用程序的应用程序委托文件相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆