From 35dd86e81ca5c73d236df24915a280bb39210161 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 14 Jan 2026 12:41:18 -0600 Subject: [PATCH] Signed-off-by: Matt Bruce --- SecureStorageSample Watch App/README.md | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 SecureStorageSample Watch App/README.md diff --git a/SecureStorageSample Watch App/README.md b/SecureStorageSample Watch App/README.md new file mode 100644 index 0000000..387b6a6 --- /dev/null +++ b/SecureStorageSample Watch App/README.md @@ -0,0 +1,58 @@ +# SecureStorageSample Watch App + +A watchOS companion app demonstrating data synchronization with the iOS app using WatchConnectivity. + +## Overview + +This watch app receives `UserProfile` data synced from the paired iPhone via `WCSession.updateApplicationContext`. It does **not** use LocalData directly for storage—instead, it displays synced data in memory. + +## Architecture + +``` +SecureStorageSample Watch App/ +├── ContentView.swift # Displays synced profile data +├── SecureStorageSampleApp.swift +├── Protocols/ +│ └── WatchDataHandling.swift # Protocol for payload handlers +├── State/ +│ └── WatchProfileStore.swift # Holds synced profile in memory +└── Services/ + ├── WatchConnectivityService.swift + └── Handlers/ + └── UserProfileWatchHandler.swift +``` + +## Data Flow + +1. **iOS app** calls `SyncHelper` when storing data with `syncPolicy: .automaticSmall` or `.manual` +2. `SyncHelper` sends data via `WCSession.updateApplicationContext` +3. **Watch app** receives context in `WatchConnectivityService` +4. The service dispatches each payload key to its registered `WatchDataHandling` handler +5. `UserProfileWatchHandler` decodes the profile and updates `WatchProfileStore` + +## Adding New Sync Payloads + +1. Create a new handler conforming to `WatchDataHandling`: + +```swift +struct MyDataWatchHandler: WatchDataHandling { + let key = "myData" + + func handle(data: Data) { + // Decode and update state + } +} +``` + +2. Register it in `WatchConnectivityService.registerDefaultHandlers()` + +## Limitations + +- **No persistent storage on watch**: Data is held in memory only +- **One-way sync**: Watch receives data from iPhone; it does not send data back +- **Simulator limitations**: WatchConnectivity may not work reliably in the simulator + +## Requirements + +- watchOS 10.0+ +- Paired with iOS app via WatchConnectivity