Skip to main content

Syncing a Portal with Live Updates

The sync operation checks Appflow for a new version of a web app used in a Portal. If an update is available, the files are downloaded and the Portal is updated to use those new files the next time it loads. The Live Updates SDK will perform a sync when the Live Update Config is added to a Portal by default. This is typically done when an app is initially launched, and requires a full restart of an app to trigger subsequent syncs. We recommend performing a sync in other situations to provide more chances for Portals to update.

Triggering a Sync

A sync can be triggered by calling the sync function in the Live Update Manager.

// Sync all configured apps
LiveUpdateManager.sync(context)

// Sync a specific app
PortalManager.sync(context, "appId")

// Sync specific apps
PortalManager.sync(context, arrayOf("appId1", "appId2"))

// Sync all configured apps and callback
LiveUpdateManager.sync(context, callback = object : SyncCallback {
override fun onAppComplete(syncResult: SyncResult) {
Log.d("LiveUpdate","CALLBACK: Sync success for app ${syncResult.liveUpdate.appId}!")
}

override fun onAppComplete(failResult: FailResult) {
Log.e("LiveUpdate","CALLBACK: Sync failed at step ${failResult.failStep.name} for app ${failResult.liveUpdate.appId}!")
}

override fun onSyncComplete() {
Log.d("LiveUpdate","CALLBACK: Sync finished!")
}
})

When to Sync

Deciding when to sync is at your discretion.

tip

Depending on the size of your web app assets, a sync operation could be expensive. Keep in mind that mobile users may be on a cellular network data connection or may be opening the app from a mininized or background state to use it.

The following example performs a sync when an app resumes as long as six hours has elapsed since the previous sync. This ensures a check is performed every time a user opens the app whether it is opened for the first time or opened from a minimized state.

// Placed in an Android Activity
override fun onResume() {
super.onResume()

// If it has been more than 6 hours since last update check, sync now.
val lastUpdateTime = LiveUpdateManager.getLastSync(this)
val now = System.currentTimeMillis()
val sixHours = 6 * 60 * 60 * 1000

if(lastUpdateTime < (now - sixHours)) {
LiveUpdateManager.sync(this)
}
}