Download - Передача состояния с iPhone на Apple Watch
![Page 1: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/1.jpg)
State transfer from iPhone to Apple Watch
Artemiy Sobolev Software Developer, Parallels Inc.
![Page 2: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/2.jpg)
Agenda
• Parallels Access for Apple Watch
• Architecture design goals
• Living objects tree
• How can it be better with watchOS 2
2
![Page 3: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/3.jpg)
Parallels Access
• Simple yet powerful remote client with great usability
3
![Page 4: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/4.jpg)
Parallels Access for Apple Watch:
Usability scenarios
• Checkout computers’ availability
• Connect/Disconnect
• Media control
4
![Page 5: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/5.jpg)
iOS 8 and watchOS 1
5
![Page 6: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/6.jpg)
iOS 8 and watchOS 1
Parent applicationWatchKit extension
App Store
WatchKit app
6
![Page 7: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/7.jpg)
iOS 8 and watchOS 1
Parent applicationWatchKit extension
App Store
WatchKit app
7
![Page 8: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/8.jpg)
iOS 8 and watchOS 1
Parent application
WatchKit extension
App Store
WatchKit app
Parent application
8
![Page 9: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/9.jpg)
Architecture design goals
• Reduce dependency for core components
• Delta updates
• Transfer changes from iPhone to Watch at any time
9
![Page 10: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/10.jpg)
Live objects tree abstraction
Process A,
Machine aProcess B,
Machine b
10
![Page 11: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/11.jpg)
Process A,
Machine aProcess B,
Machine b
Live objects tree abstraction
11
![Page 12: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/12.jpg)
Process A,
Machine aProcess B,
Machine b
Live objects tree abstraction
12
![Page 13: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/13.jpg)
Process A,
Machine aProcess B,
Machine b
Live objects tree abstraction
13
![Page 14: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/14.jpg)
Process A,
Machine aProcess B,
Machine b
Live objects tree abstraction
14
![Page 15: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/15.jpg)
Process A,
Machine aProcess B,
Machine bProcess C,
Machine c
Live objects tree abstraction
15
![Page 16: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/16.jpg)
Process A,
Machine aProcess B,
Machine bProcess C,
Machine c
Live objects tree abstraction
16
![Page 17: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/17.jpg)
Process A,
Machine aProcess B,
Machine bProcess C,
Machine c
Live objects tree abstraction
17
![Page 18: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/18.jpg)
Process A,
Machine aProcess B,
Machine bProcess C,
Machine c
Live objects tree abstraction
18
![Page 19: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/19.jpg)
Parallels Access application
Parallels Access extension
Live objects tree abstraction
19
![Page 20: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/20.jpg)
Parallels Access application
Watch app architecture
•No delegates
•No notifications
•KVO only
•Special ViewModels
20
![Page 21: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/21.jpg)
How we achieve this sync mechanism
• Reliable iCloud sync mechanism:
• NSFileCoordinator
• NSFilePresenter
• File wrappers
• NSCoding
21
![Page 22: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/22.jpg)
Turning on App Groups capability
22
![Page 23: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/23.jpg)
NSFileCoordinator + NSFilePresenter
«Don’t implement NSFilePresenter on your own»
- Dave Delong on StackOverflow
23
![Page 24: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/24.jpg)
NSFileCoordinator
• Initialized for each file operation
• Coordinates file reading and writing
• Not async
• Contains list of coordination methods
24
![Page 25: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/25.jpg)
NSFilePresenter Protocol
• Required properties:
presentedItemURL: NSURL
presentedItemOperationQueue: NSOperationQueue
• To add/remove file presenter call:
NSFileCoordinator.addFilePresenter(…)
NSFileCoordinator.removeFilePresenter(…)
25
![Page 26: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/26.jpg)
NSFilePresenter callbacks
• presentedItemDidChange
• presentedItemDidMoveToURL:
• presentedItemDidGainVersion:
• presentedItemDidLoseVersion:
• presentedItemDidResolveConflictVersion:
• NSFileVersion
26
![Page 27: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/27.jpg)
File Wrappers
Xcode.app
ContentsMacOSXcode
• Directory with extension
• Helps isolate content
• All apps and frameworks are file wrappers
27
![Page 28: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/28.jpg)
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
![Page 29: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/29.jpg)
Things to consider
• Requires minimum 3 queues
• System holds strong references to file presenters
• Memory limit for extension is ~10 MB
29
![Page 30: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/30.jpg)
watchOS 2
Watch Connectivity
Parent Application
extension
• WCSession with the Delegate
• File Transfer
• Application context
• Interactive Messaging
• User info
30
![Page 31: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/31.jpg)
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
![Page 32: Передача состояния с iPhone на Apple Watch](https://reader038.vdocuments.site/reader038/viewer/2022110108/58a7cc291a28ab6b5a8b65b9/html5/thumbnails/32.jpg)
State transfer from iPhone to Apple Watch
Artemiy Sobolev
Software Developer, Parallels Inc. c
32