WatchKit 初探
-
Upload
grady-zhuo -
Category
Technology
-
view
418 -
download
6
Transcript of WatchKit 初探
WATCHKIT 初探 Apple Watch 的概念與溝通實作
By Grady Zhuo
先來載⼀一下DEMOhttps://github.com/gradyzhuo/WatchKitDemo
https://github.com/gradyzhuo/GZNotificationCenter
WATCH APP的⾓角⾊色
Watch apps extend the behavior of existing iOS apps. The Watch app and WatchKit extension are bundled together.
from WATCHKIT TIPS FOR DEVELOPERS
WATCH APP類似WEB中CLIENT的⾓角⾊色
WATCH APP可獨⽴立運作嗎?現在不⾏行,⾼高度依賴IPHONE
需要藍⽛牙技術背景嗎?不需要,已經被 WATCHKIT 封裝了
可以使⽤用藍⽛牙技術嗎?不⾏行,可能只能抓到基本的藍⽛牙資訊
可以存取WATCH上的SENSORS嗎?
無法,但可能可以透過HEALTHKIT取得⼼心跳率的資料
LAUNCHING A WATCHKIT APP
Load initial interface controller Initialize UI Display UI
Storyboard
Launch WatchKit App
Interface Controller
willActivate
awakeWithContext:
init
WatchKit Extension
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
HOW IT WORK
HOW IT WORK
iOS App Bundle
WatchKit Extension
Code
Resource
WatchKit WatchKit
WatchKit App
Storyboard
Resource
HOW IT WORK
iOS App Bundle
WatchKit Extension
Code
Resource
WatchKit WatchKit
WatchKit App
Storyboard
Resource
HOW IT WORK
iOS App Bundle
WatchKit Extension
Code
Resource
WatchKit WatchKit
WatchKit App
Storyboard
Resource
Controller
ModalView
讓 IOS 與 WATCH 對話
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)!)
這是從WATCH APP主動呼叫那 IOS 可以主動控制嗎?
NO
確切來說是APPLE沒有在WATCHKIT中提供
What!
以前⽤用過的技巧• NSNotificationCenter
• 不可⾏行,這只在同⼀一 App 內有效,對App-Extension無效
• KVO(Key-Value-Observer)
• 不可⾏行,同上,這也無法使⽤用在⾮非同⼀一App下的物件
• Hand Off
• 可⾏行,但可能會不夠即時,也算Apple的⽅方案之⼀一。
向底層借東⻄西⽤用⽤用CFNotificationCenter
CFNotificationCenter• 這是⼀一個系統級的實作,與NSNotificationCenter ⽤用途⼀一樣,只是層級更低。
• 可使App與Extension間進⾏行通知。
• 使⽤用上有限制,無法傳遞資料,需通過NSUserDefaults、App Group或透過Server進⾏行資源共享。
TWO SIZE
38 mm 42 mm
THREE MODES
Watch App Glance Notification
SIMULATOR
SIMULATOR
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 | 逍遙⽂文⼯工作室
DEMO & 實作