WatchKit 初探

27
WATCHKIT 初探 Apple Watch 的概念與溝通實作 By Grady Zhuo

Transcript of WatchKit 初探

Page 2: WatchKit 初探

先來載⼀一下DEMOhttps://github.com/gradyzhuo/WatchKitDemo

https://github.com/gradyzhuo/GZNotificationCenter

Page 3: WatchKit 初探

WATCH APP的⾓角⾊色

Page 4: WatchKit 初探

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 初探

WATCH APP類似WEB中CLIENT的⾓角⾊色

Page 6: WatchKit 初探

WATCH APP可獨⽴立運作嗎?現在不⾏行,⾼高度依賴IPHONE

Page 7: WatchKit 初探

需要藍⽛牙技術背景嗎?不需要,已經被 WATCHKIT 封裝了

Page 8: WatchKit 初探

可以使⽤用藍⽛牙技術嗎?不⾏行,可能只能抓到基本的藍⽛牙資訊

Page 9: WatchKit 初探

可以存取WATCH上的SENSORS嗎?

無法,但可能可以透過HEALTHKIT取得⼼心跳率的資料

Page 10: WatchKit 初探

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 初探

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 初探

HOW IT WORK

Page 13: WatchKit 初探

HOW IT WORK

iOS App Bundle

WatchKit Extension

Code

Resource

WatchKit WatchKit

WatchKit App

Storyboard

Resource

Page 14: WatchKit 初探

HOW IT WORK

iOS App Bundle

WatchKit Extension

Code

Resource

WatchKit WatchKit

WatchKit App

Storyboard

Resource

Page 15: WatchKit 初探

HOW IT WORK

iOS App Bundle

WatchKit Extension

Code

Resource

WatchKit WatchKit

WatchKit App

Storyboard

Resource

Controller

ModalView

Page 16: WatchKit 初探

讓 IOS 與 WATCH 對話

Page 17: WatchKit 初探

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 初探

這是從WATCH APP主動呼叫那 IOS 可以主動控制嗎?

NO

確切來說是APPLE沒有在WATCHKIT中提供

What!

Page 19: WatchKit 初探

以前⽤用過的技巧• NSNotificationCenter

• 不可⾏行,這只在同⼀一 App 內有效,對App-Extension無效

• KVO(Key-Value-Observer)

• 不可⾏行,同上,這也無法使⽤用在⾮非同⼀一App下的物件

• Hand Off

• 可⾏行,但可能會不夠即時,也算Apple的⽅方案之⼀一。

Page 20: WatchKit 初探

向底層借東⻄西⽤用⽤用CFNotificationCenter

Page 21: WatchKit 初探

CFNotificationCenter• 這是⼀一個系統級的實作,與NSNotificationCenter ⽤用途⼀一樣,只是層級更低。

• 可使App與Extension間進⾏行通知。

• 使⽤用上有限制,無法傳遞資料,需通過NSUserDefaults、App Group或透過Server進⾏行資源共享。

Page 22: WatchKit 初探

TWO SIZE

38 mm 42 mm

Page 23: WatchKit 初探

THREE MODES

Watch App Glance Notification

Page 24: WatchKit 初探

SIMULATOR

Page 25: WatchKit 初探

SIMULATOR

Page 27: WatchKit 初探

DEMO & 實作