Передача состояния с iPhone на Apple Watch

  • View
    231

  • Download
    0

  • Category

    Mobile

Preview:

Citation preview

State transfer from iPhone to Apple Watch

Artemiy Sobolev Software Developer, Parallels Inc.

Agenda

• Parallels Access for Apple Watch

• Architecture design goals

• Living objects tree

• How can it be better with watchOS 2

2

Parallels Access

• Simple yet powerful remote client with great usability

3

Parallels Access for Apple Watch:

Usability scenarios

• Checkout computers’ availability

• Connect/Disconnect

• Media control

4

iOS 8 and watchOS 1

5

iOS 8 and watchOS 1

Parent applicationWatchKit extension

App Store

WatchKit app

6

iOS 8 and watchOS 1

Parent applicationWatchKit extension

App Store

WatchKit app

7

iOS 8 and watchOS 1

Parent application

WatchKit extension

App Store

WatchKit app

Parent application

8

Architecture design goals

• Reduce dependency for core components

• Delta updates

• Transfer changes from iPhone to Watch at any time

9

Live objects tree abstraction

Process A,

Machine aProcess B,

Machine b

10

Process A,

Machine aProcess B,

Machine b

Live objects tree abstraction

11

Process A,

Machine aProcess B,

Machine b

Live objects tree abstraction

12

Process A,

Machine aProcess B,

Machine b

Live objects tree abstraction

13

Process A,

Machine aProcess B,

Machine b

Live objects tree abstraction

14

Process A,

Machine aProcess B,

Machine bProcess C,

Machine c

Live objects tree abstraction

15

Process A,

Machine aProcess B,

Machine bProcess C,

Machine c

Live objects tree abstraction

16

Process A,

Machine aProcess B,

Machine bProcess C,

Machine c

Live objects tree abstraction

17

Process A,

Machine aProcess B,

Machine bProcess C,

Machine c

Live objects tree abstraction

18

Parallels Access application

Parallels Access extension

Live objects tree abstraction

19

Parallels Access application

Watch app architecture

•No delegates

•No notifications

•KVO only

•Special ViewModels

20

How we achieve this sync mechanism

• Reliable iCloud sync mechanism:

• NSFileCoordinator

• NSFilePresenter

• File wrappers

• NSCoding

21

Turning on App Groups capability

22

NSFileCoordinator + NSFilePresenter

«Don’t implement NSFilePresenter on your own»

- Dave Delong on StackOverflow

23

NSFileCoordinator

• Initialized for each file operation

• Coordinates file reading and writing

• Not async

• Contains list of coordination methods

24

NSFilePresenter Protocol

• Required properties:

presentedItemURL: NSURL

presentedItemOperationQueue: NSOperationQueue

• To add/remove file presenter call:

NSFileCoordinator.addFilePresenter(…)

NSFileCoordinator.removeFilePresenter(…)

25

NSFilePresenter callbacks

• presentedItemDidChange

• presentedItemDidMoveToURL:

• presentedItemDidGainVersion:

• presentedItemDidLoseVersion:

• presentedItemDidResolveConflictVersion:

• NSFileVersion

26

File Wrappers

Xcode.app

ContentsMacOSXcode

• Directory with extension

• Helps isolate content

• All apps and frameworks are file wrappers

27

File Wrappers + File Presenter

<host id>.paxhost

hostInfo.plist

img.png

• File Presenter can present directory

• The same callbacks:

presentedItem -> presentedSubitem

• All callbacks in one place

• Diminishes the need to merge changes

28

Things to consider

• Requires minimum 3 queues

• System holds strong references to file presenters

• Memory limit for extension is ~10 MB

29

watchOS 2

Watch Connectivity

Parent Application

extension

• WCSession with the Delegate

• File Transfer

• Application context

• Interactive Messaging

• User info

30

Other uses of approach

• The same mechanism with WCSession’s file transfer

• Sync state between

• iOS devices and Macs via iCloud

• iOS application and extension

• 2 iOS applications

• 2 different Mac applications

31

State transfer from iPhone to Apple Watch

Artemiy Sobolev

asobolev@parallels.com

Software Developer, Parallels Inc. c

32

Recommended