Hi,


In our mobile application, we realize that when the mobile application process is terminated and the app is relaunched, the hook to launch synchronization is the OnApplicationReady system event.

For some reason, if we use the TriggerOfflineDataSync to run the synchronization asynchronously the synchronization is not launched. If we use the OfflineDataSync to run it synchronously, it does but it comes as a downgrade of performance for the user.



Is there a way of triggering the synchronization asynchronously in this scenario?


Thanks in advance.

João Marques 

Hi João,

The reason is simple. When the OnApplicationReady runs, the object window.offlineDataSync is still undefined.

And the reason for this, is the fact that this object is created in the script OutSystemsUI.OfflineDataSync that is only require by the block OfflineDataSyncCore, and the event OnApplicationReady occurs before any block is rendered.

But this doesn't mean that you'd need to do it sync and lose performance. You can work around this "feature" with the following script in the OnApplicationReady event:

window.myApp_offlineWatcher = setInterval(
  function(){
    if(window.offlineDataSync){
       clearInterval(window.myApp_offlineWatcher);
       window.myApp_offlineWatcher = undefined;
       $actions.TriggerOfflineDataSync();
    }
  }, 50
); 

What this script does, is to check in an interval 50ms, if the object window.offlineDataSync is defined. When it is, it stops checking and triggers the Offline Data Sync action asynchronously.

Hope this helps you out.

Cheers,

RG


Hi Ruben,


Thank you very much.

It makes sense the explanation and the workaround works.


Cheers,

João