apple-watch - 如何向现有 Apple Watch 应用添加并运行 Glance?

标签 apple-watch watchos-2

我的 iOS 项目中有一个现有的 Apple Watch 应用。

如何向现有项目添加 Glance?

最佳答案

您实际上不需要编辑现有目标的方案,尽管您当然可以。

如果您已完成 Apple Watch 目标设置并添加到现有应用程序中,并且只想添加和构建 Glance View ,则可以按照 developer.apple.com 中的步骤操作。 .

Apple Watch 应用程序受到界面构建器的严格控制。添加一个新的(仅添加一个!)Glance Interface Controller 到 Storyboard并指定自定义类名就足够了; Apple Watch 将自动加载您的 Glance 界面 Controller 。

  1. 向 Storyboard添加新的Glance 界面 Controller :

    enter image description here

  2. 将新文件添加到您的扩展中,例如命名为GlanceInterfaceController.swift,确保它是您的扩展程序的成员:

    enter image description here

    enter image description here

  3. 您的新 GlanceInterfaceController.swift 应该是 WKInterfaceController 的子类:

    import Foundation
    import WatchKit
    
    class GlanceInterfaceController: WKInterfaceController {
    
        override func awakeWithContext(context: AnyObject?) {
    
            super.awakeWithContext(context)
        }
    }
    
  4. 在界面生成器中指定此自定义类作为新 Glance 界面 Controller 的 Controller :

    enter image description here

将您的应用构建到 Apple Watch 或模拟器上。在您在 watch 设置中将其打开之前,Glance 不会出现在一览中:

enter image description here

enter image description here

关于apple-watch - 如何向现有 Apple Watch 应用添加并运行 Glance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31130481/

相关文章:

ios - WatchOS2网络通讯

ios - Xcode 的 Watchkit 中带有滚动表的静态背景 (Apple Watch)

swift - 无效的 Swift 支持 - SwiftSupport 文件夹丢失

watchkit - 在 watchOS 2 下处理复杂功能

ios - 可以从 iOS 应用程序打开 watchOS 应用程序吗?

swift watch 套件 : startUpdatingLocation() is unavailable

watchkit - Apple Watch 中的 PubNub 框架

ios - 反馈振动像苹果呼吸一样 swift

xcode - iOS - Watch Companion 应用程序中未显示应用程序图标

ios - 在使用 WatchConnectivity 将数据从 WatchOs 传输到 iOs 时,是否有任何代表来监控进度?