Offline and Sync
The MOSA SDK is designed with an offline-first architecture, allowing dock operations to work without internet connectivity and automatically syncing data when connectivity is restored.
Offline Behavior
What Works Offline
The SDK supports the following operations offline:
- Dock Operations: Unlock and lock operations work completely offline once an unlock key is obtained
- Session Events: All session events are queued locally for sync
- Key Caching: Unlock keys are cached locally and can be reused until expiry
- Session Data: Session data is stored locally and persists across app restarts
What Requires Internet
The following operations require internet connectivity:
- Requesting Unlock Keys: Initial key requests require backend connectivity
- Data Sync: Syncing queued events to backend requires connectivity
Offline Limits
- Key Expiry: Keys expire after a certain time (each key might have different expiry time) regardless of connectivity
- Event Queue: Events are queued locally but should be synced regularly
Sync Patterns
Automatic Sync
The SDK automatically syncs data when:
- Connectivity Restored: When internet connectivity is detected
- Periodic Sync: Background sync every 30 minutes (when app is active)
- App Launch: Sync on app launch if pending events exist
Manual Sync
You can manually trigger sync:
- Android
- iOS
- Flutter
lifecycleScope.launch {
sdk.forceSyncNow()
}
Task {
await sdk.forceSyncNow()
}
await mosaDockSdk.forceSyncNow();
Sync Status
Monitor sync status:
- Android
- iOS
- Flutter
// Check if syncing
val isSyncing = sdk.isSyncingStateFlow().value
// Get pending events count
val pendingCount = sdk.getPendingEventsCount()
// Observe sync state
sdk.isSyncingStateFlow().collect { syncing ->
if (syncing) {
// Show sync indicator
}
}
// Check if syncing
let isSyncing = sdk.isSyncing
// Get pending events count
let pendingCount = await sdk.getPendingEventsCount()
// Observe sync state (using Combine)
sdk.syncStatePublisher
.sink { syncing in
if syncing {
// Show sync indicator
}
}
// Check pending events count
final pendingCount = await mosaDockSdk.getPendingEventsCount();
// Listen to sync state events
mosaDockSdk.syncStateEvents.listen((event) {
final isSyncing = event.syncing;
if (isSyncing) {
// Show sync indicator
}
});
Next Steps
- SDK Callbacks - Event handling during sync
- Testing and Debugging - Troubleshooting sync issues
For platform-specific details, see the Platform Guides.