Skip to main content
Applications often need to sync data when they’re not in active use. This document explains background syncing implementations with PowerSync.

Platform Support

Background syncing has been tested in: These examples can be adapted for other platforms/frameworks. For implementation questions or assistance, chat to us on Discord.

Flutter Implementation Guide

Prerequisites

  1. Complete the workmanager platform setup
  2. Review the Supabase To-Do List Demo for context

Configure the Background Task

In main.dart:
Note specifically in the switch statement:
  1. Since WorkManager executes in a new process, you need to set up the PowerSync local database and connect to the remote database using your connector.
  2. Run a write (in the case of this demo app, we create a ‘todo list’)
  3. Make sure to run currentConnector.uploadData(db); so that the local write is uploaded to the remote database.

Testing

Add a test button:
Click the button, background the app, wait 10 seconds, then verify new records in the remote database.

Platform Compatibility

Android

  • Implementation works as expected.

iOS

  • At the time of last testing this (January 2024), we were only able to get part of this to work using the branch for this PR into workmanager.
  • While testing we were not able to get iOS background fetching to work, however this is most likely an issue with the package.