Download - WatchKit 初探
![Page 1: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/1.jpg)
WATCHKIT 初探 Apple Watch 的概念與溝通實作
By Grady Zhuo
![Page 2: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/2.jpg)
先來載⼀一下DEMOhttps://github.com/gradyzhuo/WatchKitDemo
https://github.com/gradyzhuo/GZNotificationCenter
![Page 3: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/3.jpg)
WATCH APP的⾓角⾊色
![Page 4: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/4.jpg)
Watch apps extend the behavior of existing iOS apps. The Watch app and WatchKit extension are bundled together.
from WATCHKIT TIPS FOR DEVELOPERS
![Page 5: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/5.jpg)
WATCH APP類似WEB中CLIENT的⾓角⾊色
![Page 6: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/6.jpg)
WATCH APP可獨⽴立運作嗎?現在不⾏行,⾼高度依賴IPHONE
![Page 7: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/7.jpg)
需要藍⽛牙技術背景嗎?不需要,已經被 WATCHKIT 封裝了
![Page 8: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/8.jpg)
可以使⽤用藍⽛牙技術嗎?不⾏行,可能只能抓到基本的藍⽛牙資訊
![Page 9: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/9.jpg)
可以存取WATCH上的SENSORS嗎?
無法,但可能可以透過HEALTHKIT取得⼼心跳率的資料
![Page 10: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/10.jpg)
LAUNCHING A WATCHKIT APP
Load initial interface controller Initialize UI Display UI
Storyboard
Launch WatchKit App
Interface Controller
willActivate
awakeWithContext:
init
WatchKit Extension
![Page 11: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/11.jpg)
The life cycle of an interface controller
Display UI User interacts with UI
User stops interacting
Interface Controller
willActivate didDeactivateVarious action methods
WatchKit Extension
Suspendextension
![Page 12: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/12.jpg)
HOW IT WORK
![Page 13: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/13.jpg)
HOW IT WORK
iOS App Bundle
WatchKit Extension
Code
Resource
WatchKit WatchKit
WatchKit App
Storyboard
Resource
![Page 14: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/14.jpg)
HOW IT WORK
iOS App Bundle
WatchKit Extension
Code
Resource
WatchKit WatchKit
WatchKit App
Storyboard
Resource
![Page 15: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/15.jpg)
HOW IT WORK
iOS App Bundle
WatchKit Extension
Code
Resource
WatchKit WatchKit
WatchKit App
Storyboard
Resource
Controller
ModalView
![Page 16: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/16.jpg)
讓 IOS 與 WATCH 對話
![Page 17: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/17.jpg)
APPLE的⽅方案• class func openParentApplication(userInfo: [NSObject : AnyObject], reply: (([NSObject :
AnyObject]!, NSError!) -> Void)?) -> Bool
openParentApplication:reply:
reply:
背景模式喚醒App
application:handleWatchKitExtensionRequest:reply:
reply([“ShowText”: “Hello”])
• func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!)
![Page 18: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/18.jpg)
這是從WATCH APP主動呼叫那 IOS 可以主動控制嗎?
NO
確切來說是APPLE沒有在WATCHKIT中提供
What!
![Page 19: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/19.jpg)
以前⽤用過的技巧• NSNotificationCenter
• 不可⾏行,這只在同⼀一 App 內有效,對App-Extension無效
• KVO(Key-Value-Observer)
• 不可⾏行,同上,這也無法使⽤用在⾮非同⼀一App下的物件
• Hand Off
• 可⾏行,但可能會不夠即時,也算Apple的⽅方案之⼀一。
![Page 20: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/20.jpg)
向底層借東⻄西⽤用⽤用CFNotificationCenter
![Page 21: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/21.jpg)
CFNotificationCenter• 這是⼀一個系統級的實作,與NSNotificationCenter ⽤用途⼀一樣,只是層級更低。
• 可使App與Extension間進⾏行通知。
• 使⽤用上有限制,無法傳遞資料,需通過NSUserDefaults、App Group或透過Server進⾏行資源共享。
![Page 22: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/22.jpg)
TWO SIZE
38 mm 42 mm
![Page 23: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/23.jpg)
THREE MODES
Watch App Glance Notification
![Page 24: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/24.jpg)
SIMULATOR
![Page 25: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/25.jpg)
SIMULATOR
![Page 26: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/26.jpg)
RESOURCES• WATCHKIT TIPS FOR DEVELOPERS
• WatchKit: Using Handoff in an Apple Watch App
• “My Biggest WatchKit Mistake”
• WatchKit: Initial Impressions
• App与Extensions间通信共享数据
• WatchKit - Zonble
• [iOS] Watch App Architecture | 逍遙⽂文⼯工作室
![Page 27: WatchKit 初探](https://reader031.vdocuments.pub/reader031/viewer/2022012313/55b54db9bb61eb2e6a8b4736/html5/thumbnails/27.jpg)
DEMO & 實作