简体   繁体   English

Apple Watch app入口点

[英]Apple watch app entry point

In xcode you need to specify the initial interface controller for the watch app, which is the entry point of the watch app, shown first when you open it. 在xcode中,您需要为监视应用程序指定初始界面控制器,这是监视应用程序的入口点,在您打开它时首先显示。

But is it shown every time you open the watch app? 每次打开手表应用程序时都会显示它吗? For example you open a watch app, navigate to a page, close it, and open it again. 例如,您打开一个监视应用程序,导航到一个页面,关闭它,然后再次打开它。 Does it open on the page you were last time (like on iOS), or again on the first interface controller? 它是在上次的页面上打开(比如在iOS上),还是在第一个接口控制器上打开?

According to apple documentation : 根据苹果文档

Normally, WatchKit displays the first interface controller in the sequence initially. 通常,WatchKit最初会显示序列中的第一个接口控制器。

Well, normally is not every time. 好吧,通常不是每次都这样。 I looked through watch app videos from the watch presentation event, but there wasn't a case when they opened an app twice. 我查看了手表演示活动中的观看应用视频,但是当他们两次打开应用时没有出现这种情况。

That's a great question! 这是一个很好的问题!

Main Entry Point 主要切入点

First off, you can certainly avoid showing that MainInterfaceController each time. 首先,您当然可以避免每次都显示MainInterfaceController See this thread for more information where I detail exactly how to use that entry point to launch the appropriate set of InterfaceController objects. 有关详细信息,请参阅此线程 ,其中详细说明了如何使用该入口点来启动适当的InterfaceController对象集。

Watch Extension Lifecycle 观看扩展生命周期

It is VERY important to understand what the expected lifecycle of a Watch Extension actually is. 了解Watch Extension的预期生命周期实际上是非常重要的。 It will only run while the user has the Watch up and is running your app. 它只会在用户启动并运行您的应用程序时运行。 This will generally be 1-5 seconds (opinionated value). 这通常是1-5秒(固定值)。 As soon as the user lowers their wrist, your Watch Extension will be terminated completely. 一旦用户放下手腕,您的Watch Extension将完全终止。 Therefore, it is going to be restarted every time at the same entry point. 因此,它将在每次在同一入口点重新启动。 This means that you need to track your app state if you want to launch a different page set in the MainInterfaceController . 这意味着如果要在MainInterfaceController启动不同的页面集,则需要跟踪应用程序状态。

Hopefully that helps shed some light. 希望这有助于揭示一些亮点。

If your WatchKit extension is still running, it will pick up where you left off. 如果您的WatchKit扩展程序仍在运行,它将从您上次停止的地方继续运行。 If not, and everything has been dumped out of memory, it should start again with your initial interface controller. 如果没有,并且所有内容都已从内存中转储,则应该使用初始接口控制器重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM