0
votes

we have an app which uses JSONStore to support offline, if device is offline and user submit data it stores it offline, now when device is online and when user login to the app it sync with server and submit all data to server.

the question is, Is it possible when device comes online then my offline data sync with server without user open my app ?

Does worklight support that? Or I have to do something else?

please advice

1
Worklight does not support this; the application needs to be launched.Idan Adar

1 Answers

3
votes

Like Idan said, Worklight does not support this, but depending on the OS, it could support it.

For instance, on Android, you could use BroadcastReceivers to detect changes in network connectivity, and execute an action when it happens, regardless of whether your app is closed or not.

Here is the API for the receiver: http://developer.android.com/reference/android/content/BroadcastReceiver.html and here is a SO answer explaining how to use it to detect WiFi connectivity: https://stackoverflow.com/a/22626736/2245921 So you can modify this BroadcastReceiver to run the sync code that you would normally do if your app was already open.

If you are using any other platform (iOS, Windows) there might be an equivalent that you can use.

Also, keep in mind that if you are doing a hybrid application, you can create your own Cordova plugin to execute native code from Javascript. Here is the documentation on how to do so: http://cordova.apache.org/docs/en/3.5.0/guide_hybrid_plugins_index.md.html#Plugin%20Development%20Guide