sync static method
Manually execute upload configured Config.url
If the plugin is configured for HTTP with an Config.url and Config.autoSync false
, the sync method will initiate POSTing the locations currently stored in the native SQLite database to your configured Config.url.
When your HTTP server returns a response of 200 OK
, that record(s) in the database will be DELETED.
If you configured Config.batchSync true
, all the locations will be sent to your server in a single HTTP POST request, otherwise the plugin will execute an HTTP post for each Location in the database (REST-style).
Your callback will be executed and provided with a List
of all the locations from the SQLite database. If you configured the plugin for HTTP (by configuring a Config.url, your callback will be executed after all the HTTP request(s) have completed.
If the plugin failed to sync to your server (possibly because of no network connection), the failure callback will be called with an error message. If you are not using the HTTP features, sync will delete all records from its SQLite database.
Example
BackgroundGeolocation.sync((List records) {
print('[sync] success: ${records}');
}).catchError((error) {
print('[sync] FAILURE: ${error}');
});
NOTE: For more information, see the HTTP Guide at HttpEvent.
Implementation
static Future<List> sync() async {
return (await _methodChannel.invokeListMethod('sync')) as FutureOr<List>;
}