zoukankan      html  css  js  c++  java
  • Apple Watch: WatchKit 应用程序要点

           Apple Watch: WatchKit 应用程序要点

    本文译自:Apple Watch: WatchKit App Essentials

    WatchKit 应用程序架构

    上一篇文章简单介绍了 WatchKit,在开发 Apple Watch 应用程序时由两部分构成:WatchKit 应用程序和 WatchKit 扩展。

    • WatchKit 应用程序是一个运行在 Apple Watch 中的可执行文件。它包括 storyboard 和渲染屏幕时所需的资源文件。
    • WatchKit 扩展则是运行在 iPhone 上的可执行文件。包括管理应用程序界面的逻辑代码,以及处理用户的交互操作。

    为了程序界面的正常使用,这两部分需要一起运行。用户与应用程序交互的典型步骤如下:

    1. 用户与 WatchKit 应用程序交互。
    2. WatchKit 应用程序分析交互情况,并选择将被管理的 storyboard。
    3. WatchKit 与 iPhone 通讯,以运行 WatchKit 扩展。
    4. WatchKit 扩展初始化并创建需要提供给 WatchKit 应用程序 storyboard 使用的对象。
    5. Storyboard 根据 WatchKit 扩展创建的对象,生成 scene,并将其显示到 Apple Watch 中。
    6. WatchKit 应用程序和 WatchKit 将会共享一些信息,直到用户停止使用 WatchKit 应用程序。此时,iOS 将使 WatchKit 扩展休眠,直到有新的用户交互。

    下面的这个图演示了这个流程:

    上图中有个重要的概念就是 storyboard 响应用户的操作并配置需要显示的屏幕内容的方法。这归功于 interface controller对象 (WKInterfaceController的实例),相当于 iOS 中的 view controller。

    与 view controller 不同的是 interface controller 不管理屏幕中实际的 view,WatchKit 以透明的方式对 view 进行处理。一般,一个 WatchKit 应用程序会有多个 interface controller,用来显示不同的数据类型,只不过同时只显示一个罢了。

    WatchKit 应用程序的生命周期

    一个 WatchKit 应用程序的启动方式有 3 种:

    • 用户点击 Apple Watch 主屏幕上的图标。
    • 用户与应用程序的 glance 交互。
    • 用户与通知交互。

    上面的每种方式都将初始化 WatchKit 应用程序和 WatchKit 扩展。根据上面不同的启动方式,WatchKit 会利用相应的 storyboard 加载 scene,并请求 WatchKit 扩展初始化相应的 interface controller。

    下面的图演示了相关过程:

    如图所示,在用户界面中,interface controller 对象管理着相关交互。当用户与 Apple Watch 上的应用程序交互时,WatchKit 扩展会运行。一旦用户停止交互或者从程序中退出,iOS 将关闭当前的 interface controller,并休眠扩展。在用户和 Apple Watch 之间,这样的交互方式非常简洁,interface controller 应该是轻量级的,并且快速的执行任务。

    下面的图演示了相关过程:

  • 相关阅读:
    ASP.NET存储Session的StateServer
    EasyUI中DataGrid构建复合表头
    EasyUI使用DataGrid向服务器传参
    CentOS 7 U盘安装问题解决
    对指定表的某一列数据合并单元格
    常用的一些sql
    Oracle数据库表空间常用操作
    修改Oracle redo.log文件的大小
    UOJ 非传统题配置手册
    UOJ552 【UNR #4】同构判定鸭【线性代数,哈希】
  • 原文地址:https://www.cnblogs.com/XieMinQiang/p/5276382.html
Copyright © 2011-2022 走看看