Watch os 2.0

72
@Hack into the City ᤈ㵕膏绝ಀୗੜ肞 Play with watchOS 2.0 by Grady Zhuo [email protected]

Transcript of Watch os 2.0

Page 1: Watch os 2.0

@Hack into the City

Play with watchOS 2.0 by Grady [email protected]

Page 2: Watch os 2.0

Sample Code

https://goo.gl/oTo8PV

Page 3: Watch os 2.0

How it Work? (watchOS 1)

WatchKit ExtensionWatchKit UI

iOS App

WatchKit WatchKit

Page 4: Watch os 2.0

How it Work? (watchOS 1)

WatchKit ExtensionWatchKit UI

iOS App

WatchKit WatchKit

Page 5: Watch os 2.0

Modified on Architecture

WatchKit ExtensionWatchKit UI

iOS App

Page 6: Watch os 2.0

Available Hardwares

WatchKit Extension

WatchKit UIDigital Crown

Taptic Engine

Networking

Microphone

Heart Rate Sensor

Accelerometer

Gyroscope

Page 7: Watch os 2.0

Available System Technologies

WatchKit Extension

WatchKit UI

ClockKitContacts Core Data Core Foundation Core Graphics Core Location Core Motion EventKit Foundation HealthKit

HomeKit ImageIO MapKit Mobile Core Services PassKit Security System Configuration Watch Connectivity WatchKit

Page 8: Watch os 2.0

Available System Technologies

❖ WatchConnectivity

❖ Complication - ClockKit

❖ Digital Crown - WKInterfacePicker

❖ Haptic - WKInterfaceDevice

❖ MediaPlayer - WKInterfaceController

❖ AudioRecording - WKInterfaceController

Page 9: Watch os 2.0

How do you get data to the watch App?

Page 10: Watch os 2.0
Page 11: Watch os 2.0

WatchConnectivity NSURLSession

Page 12: Watch os 2.0

WatchConnectivity

The Watch Connectivity framework (WatchConnectivity.framework) provides a two-way communications conduit between an iOS app and a WatchKit app on a paired Apple Watch.

Page 13: Watch os 2.0

WatchConnectivity

The Watch Connectivity framework (WatchConnectivity.framework) provides a two-way communications conduit between an iOS app and a WatchKit app on a paired Apple Watch.

Page 14: Watch os 2.0

Setup

if (WCSession.isSupported()) {

let session = WCSession.defaultSession()

session.delegate = self // conforms to WCSessionDelegate

session.activateSession() }

Page 15: Watch os 2.0

Session State

Page 16: Watch os 2.0

Session State

paired

Page 17: Watch os 2.0

Session State

watchAppInstalled

paired

Page 18: Watch os 2.0

Session State

watchAppInstalled

paired

complicationEnabled

Page 19: Watch os 2.0

Session State

watchAppInstalled

reachable

paired

complicationEnabled

Page 20: Watch os 2.0

Session State

watchAppInstalled

reachable

paired

complicationEnabledreachable

Page 21: Watch os 2.0

3 + 1 Transfer Types❖ Background transfers

• Application context

• User info transfer

• File transfer

❖ Interactive messaging

• Live communication

Background transfers

Page 22: Watch os 2.0

Background transfers ❖ Content not needed immediately

❖ OS intelligently transfers content

❖ Queue up content

❖ OS transfers content

❖ Sending side can exit

• Pick opportune time

• Delivers on receiver next launch

Page 23: Watch os 2.0

Background transfers ❖ Content not needed immediately

❖ OS intelligently transfers content

❖ Queue up content

❖ OS transfers content

❖ Sending side can exit

• Pick opportune time

• Delivers on receiver next launch

Recommended

Page 24: Watch os 2.0

3 + 1 Transfer Types❖

• Application context

• User info transfer

• File transfer

❖ Interactive messaging

• Live communication

Background transfers

Page 25: Watch os 2.0

Application context ❖ Most interesting/relevant content

❖ Overriding behavior

❖ Dictionary

❖ Property list types

❖ Recommended use cases

• Many Apple Watch apps

• Glances

Page 26: Watch os 2.0

applicationContext receivedApplicationContext

Page 27: Watch os 2.0

applicationContext receivedApplicationContext

iOS App

Page 28: Watch os 2.0

iOS App

applicationContext receivedApplicationContext

A

update

Page 29: Watch os 2.0

iOS App

applicationContext receivedApplicationContext

A

B

update

A

Page 30: Watch os 2.0

applicationContext

B

iOS App

receivedApplicationContext

B A

Page 31: Watch os 2.0

applicationContext

B

iOS App

receivedApplicationContext

BB

Watch Extension

Page 32: Watch os 2.0

applicationContext

B

iOS App

receivedApplicationContext

B

Current B

B

Page 33: Watch os 2.0

User info transfer

❖ Queue user infos (dictionaries)

❖ Property list types(String, Number, Array, Dictionary…)

❖ In memory content

❖ Access to outstanding content in queue

Page 34: Watch os 2.0

Background Queue Outstanding User Info Transfers

Page 35: Watch os 2.0

Background Queue Outstanding User Info Transfers

Watch Game

Page 36: Watch os 2.0

Background Queue Outstanding User Info Transfers

L1

Page 37: Watch os 2.0

Background Queue Outstanding User Info Transfers

L1

L2

Page 38: Watch os 2.0

Background Queue Outstanding User Info Transfers

L1 L2

L3

Page 39: Watch os 2.0

Background Queue Outstanding User Info Transfers

L1 L2 L3

Page 40: Watch os 2.0

iOS Game

Background Queue Outstanding User Info Transfers

L1 L2 L3

L1

didReceiveUserInfo

Page 41: Watch os 2.0

iOS Game

didReceiveUserInfo

Background Queue Outstanding User Info Transfers

L2 L3

L1L2

Page 42: Watch os 2.0

Background Queue Outstanding User Info Transfers

L3

iOS Game

L1L2

L3

didReceiveUserInfo

Page 43: Watch os 2.0

File transfer

❖ Very similar to user info transfer

❖ Queue files

❖ Access to outstanding content in queue

❖ Additional metadata

❖ Small

• Property list types

Page 44: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

Page 45: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

A

Page 46: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

B

A

Page 47: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

A B

C

Page 48: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

A B C

Page 49: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

A B C

Watch Extension

Page 50: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

A B C

didReceiveFile

A

Page 51: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

B C

didReceiveFile

A

B

Page 52: Watch os 2.0

Outstanding File Transfers ~/Documents/Inbox/

iOS App

C

didReceiveFile

A

B

C

Page 53: Watch os 2.0

Live communication

❖ Devices connected Watch

❖ Check reachable == true

❖ Small

• Property list types

Page 54: Watch os 2.0
Page 55: Watch os 2.0

iOS App

session.reachable == trueWatch

Extension

Page 56: Watch os 2.0

iOS App

session.reachable == true

sendMessage:

Watch Extension

A

Page 57: Watch os 2.0

iOS App

session.reachable == trueWatch

ExtensionR

Page 58: Watch os 2.0

iOS App

session.reachable == trueWatch

Extension

replyHandler()

R

Page 59: Watch os 2.0

Live communication func sendMessage( message: [String : AnyObject], replyHandler: (([String : AnyObject]) -> Void)?, errorHandler: ((NSError) -> Void)?)

optional func session( session: WCSession, didReceiveMessageData messageData: NSData, replyHandler: (NSData) -> Void)

On Receiver side (by delegate)

On Sender Side

Page 60: Watch os 2.0

Clock Face

Page 61: Watch os 2.0

Clock Face

Page 62: Watch os 2.0

Complication

Page 63: Watch os 2.0

Complication Families

Page 64: Watch os 2.0

CLKComplicationTemplate

Page 65: Watch os 2.0

CLKComplicationTemplate ModularLargeStandardBody

class CLKComplicationTemplateModularLargeStandardBody : CLKComplicationTemplate { var headerTextProvider : CLKTextProvider var body1TextProvider : CLKTextProvider var body2TextProvider : CLKTextProvider? var headerImageProvider : CLKImageProvider?}

Page 66: Watch os 2.0

CLKComplicationDataSource

CLKComplicationServer

Reload

Timeline

WatchKit Extension

Time Travel

Page 67: Watch os 2.0

Timeline9:00

Lunch!12:00 PM

12:00

Coffee!1:30 PM

1:30

Dinner!6:30 PM

Timeline Entry9:00

Lunch!12:00 PM

Timeline Entry12:00

Coffee!1:30 PM

Timeline Entry1:30

Dinner!6:30 PM

9:00 12:00 1:00 2:00

Page 68: Watch os 2.0

Time Travel

Page 69: Watch os 2.0

Configure

Page 70: Watch os 2.0

Configure

Page 71: Watch os 2.0

Summary❖ Extension has been moved to on Watch.

❖ All the most hardware API on the Watch can be used.

❖ Connect with iOS App by WatchConnectivity.

❖ Complications can be provided by Watch App.

❖ Almost all CocoaTouch frameworks are supported.

❖ Now you can play Taptic Engine.

❖ Digital Crown can be used on Simulator.

Page 72: Watch os 2.0

Thanks for your attention