Sync & Network Status
Notify a user of the sync status of the platform and react to changes in network availability
Overview
Cloneable will sync data to and from it's backend servers as well as files from cloud file storage. While these sync changes occur, it's important to show the user the current status of sync.
Network Status
The CloneablePlatform
class provides a Published variable named networkConnected
which is an enum that will update as network status changes. The enum has the following states:
public enum CloneableConnectionState {
case connecting
case connected
case disconnected
}
// example usage
struct CloneableStatus: View {
@EnvironmentObject var cloneable: CloneablePlatform
var body: some View {
if cloneable.networkStatus == .disconnected {
// show disconnected
} else {
// show connected
}
}
}
Sync Status
As mentioned above, the Cloneable SDK syncs both data and files from the backend. Monitor changes to the sync status changes by watching the syncStatus
. This is also an enum with the following states
public enum CloneableSyncStatus {
case syncing
case synced
case sync_error
}
// example usage
struct CloneableStatus: View {
@EnvironmentObject var cloneable: CloneablePlatform
var body: some View {
if cloneable.syncStatus == .synced {
// show platform is synced
} else {
// show other cases
}
}
}
Monitor File Sync Status
If files are syncing or need to sync the SDK exposes a Published variable named numFilesToSync
which monitors the total number of files that still are un-synced both to and from cloud storage. The variable is an Int.
/// example usage
struct CloneableStatus: View {
@EnvironmentObject var cloneable: CloneablePlatform
var body: some View {
if cloneable.syncStatus == .syncing {
// Get the total number of files we still need to show
Text(String(cloneable.numFilesToSync) + " files to sync")
} else {
// show other cases
}
}
}
Get total number of files downloaded
The SDK exposes a function to get the total number of downloaded files getNumberOfDownloadedFiles()
/// example usage
struct CloneableStatus: View {
@EnvironmentObject var cloneable: CloneablePlatform
var body: some View {
// Get the total number of files downloaded
Text(String(cloneable.getNumberOfDownloadedFiles()) + " files downloaded")
}
}
Last updated