Domanda

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):

enter image description here

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

È stato utile?

Soluzione

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?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top