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

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

问题描述

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

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:

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

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,请创建一个新的Notification Interface Controller,并为Notification Category创建一个唯一的名称.如果您需要其他自定义,请参阅管理自定义Long在文档中查看界面.具体来说:

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加载适当的情节提要板资源并准备如图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",
    }
}

(如果您使用的是 local 通知,而不是推送通知,只需在 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.

另请参见 查看全文

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