IBM Worklight - How can I execute JavaScript code before updating the application?

我们两清 提交于 2019-12-11 12:51:50

问题


When a new software update is available, if user has data stored in jsonstore I need to allow user to commit them to the server before applying the software update, so his/her uncommited updates don't get lost. Currently user is unable to use the application until the update is installed.

Is there a way to execute JavaScript code before updating the application so I can initialize the jsonstore, take the data and send to the adapter before performing the update installation?


回答1:


There is no programmatic hook available for a developer to use in order to perform an action prior to a Direct Update request.

That said, a Direct Update does not take place during runtime per-se, rather only:

  1. Upon application initialization
  2. Upon returning from the background to the foreground

So from what I understand, only the second scenario above is not being handled.
In the first scenario the user did not yet perform any data manipulations.


Not sure I completely understand the scenario, as you didn't elaborate much, but...
A possible solution would be to use the Cordova Events API (pause, resume).

In theory, you could detect the case where the application was tasked with moving to the background and hopefully save the user data in a secondary collection before that.

And so, when the app is resumed but a Direct Update request has arrived and the primary collection was not previously saved/synced with the server (check with some flag, maybe?) then you could restore the app state using the secondary collection; essentially resume the app with the "unsaved" user data despite the Direct Update request. You/the user could then save and sync the data.

Or something like that.
Feel free to also submit a feature request.




回答2:


We saw that the "unload" and "beforeunload" events are fired before a DirectUpdate. Maybe this is an option for code if the data is still available in memory at that point in time?

WL 5.0.6.1 Android - Direct Update keeps Native/Cordova resources active/in memory (e.g. BusyIndicator) but reference is lost



来源:https://stackoverflow.com/questions/18020957/ibm-worklight-how-can-i-execute-javascript-code-before-updating-the-applicatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!