我的 iOS 项目中有一个现有的 Apple Watch 应用。
如何向现有项目添加 Glance?
最佳答案
您实际上不需要编辑现有目标的方案,尽管您当然可以。
如果您已完成 Apple Watch 目标设置并添加到现有应用程序中,并且只想添加和构建 Glance View ,则可以按照 developer.apple.com 中的步骤操作。 .
Apple Watch 应用程序受到界面构建器的严格控制。添加一个新的(仅添加一个!)Glance Interface Controller 到 Storyboard并指定自定义类名就足够了; Apple Watch 将自动加载您的 Glance 界面 Controller 。
向 Storyboard添加新的Glance 界面 Controller :
将新文件添加到您的扩展中,例如命名为
GlanceInterfaceController.swift
,确保它是您的扩展程序的成员:您的新
GlanceInterfaceController.swift
应该是WKInterfaceController
的子类:import Foundation import WatchKit class GlanceInterfaceController: WKInterfaceController { override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) } }
在界面生成器中指定此自定义类作为新 Glance 界面 Controller 的 Controller :
将您的应用构建到 Apple Watch 或模拟器上。在您在 watch 设置中将其打开之前,Glance 不会出现在一览中:
关于apple-watch - 如何向现有 Apple Watch 应用添加并运行 Glance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31130481/