Watch Kit 开发一瞥
创建项目
-
一下是在已经创建的iphone app的基础上进行的操作:
-
1、添加target
-
2、选择WatchKit App
-
3、填写Target信息,此处可以选择是否支持 Notification 和 Glance。
-
Watch App 的运行机制
创建完项目后我们可以看到多出了来两个group 这个两个group 分别是WatchKit Extension和WatchKit App. WatchKit Extension 即 运行在iphone上的WatchKit App的辅助程序,主要用来处理事件数据等, WatchKit App 运行在apple watch 上程序,用于展示。
- watch app 的加载机制,如下图:
- watchkit 的 interface controller 的生命周期: 如下图:
-
三种接口类型的实现
-
The WatchKit App
///数据初始化 - (instancetype)init { self = [super init]; if (self) { //Fetch the data you want to display. } return self; } ///页面布局参数设置 - (void)awakeWithContext:(id)context { [super awakeWithContext:context]; //Set the initial values and configuration of labels, images, and other controls. Configure interface objects here. NSLog(@"%@ awakeWithContext", self); } ///当controller将显示在屏幕上的时候调用 - (void)willActivate { // This method is called when watch view controller is about to be visible to user NSLog(@"%@ will activate", self); } ///当controller即将不显示在屏幕上的时候调用 - (void)didDeactivate { // This method is called when watch view controller is no
-