Worklight - connection on startup fails

試著忘記壹切 提交于 2019-12-25 06:34:33

问题


using Worklight server v6.1 i'm trying to develop a simple app that connects to the production server at startup. To get this i do:

  • in initOptions.js file i set connectOnStartup to true
  • in wlCommonInit method of <my-app>.js file i call :

    WL.Client.connect({ onSuccess: connected, onFailure: failure });

where connected and failure are two callback to two simple functions that load some data in a listview. When i trie it on a production or development environment i get a spot over my app's layout stating it's loading as you can see in the pic below(even if the application loaded data correctly):

i notice that after installing and running it on an iOS or Android device i don't have this strange behaviour, but on Windows8 devices i do have.

i set to false connectOnStartup and left only the call to WL.Client.connect. Now the app doesn't get blocked anymore(i suppose becouse WL.Client.connect runs asynchronously while WL.Client.init does not but it's only my opinion).

i can't connect to the server yet, this is strange becouse(you can see in the pic) there is a listview filled with data returned by a sql adapter,

so it looks like the app can connect to the server for calling adapters but not for updates


回答1:


You have already set connectOnStartup:true in initOption.js, this means that the app will try to connect to the Worklight Server on startup - basically it calls to connect, so why do you call WL.Client.connect in wlCommonInit() as well?

As for the onSuccess and onFailure, I think that in this what you may want is the following:
See the options for WL.Client.init.

There is an initOption that you can uncomment in initOptions.js:

  • onConnectionFailure

A failure-handling function invoked when connection to the Worklight Server, performed on initialization by default, or if the connectOnStartup flag is true, fails.

The "success" by default is wlCommonInit(), but you want something else then in initOptions.js you can also add onSuccess: something.


BTW, where did you see what you've done as a "best practice" by Worklight?



来源:https://stackoverflow.com/questions/21402243/worklight-connection-on-startup-fails

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