Worklight - getUserPref doesn't persist/load b

2019-09-02 23:04发布

问题:

I'm trying to persist some data for the user in this WL app using:

WL.Client.setUserPref('foo', 'bar');

and getting it back by using

WL.Client.getUserPref('key');

My target environment is Windows 8.1 with the latest Worklight Studio (6.2.0.01-20141015).

With a user logged in, I have tested this in:

  • Preview Mode
    • Logged a user in
    • Set a user pref
    • Logged out
    • Closed window/tab
    • Opened, logged in again
    • Get back user pref (null)

Using the developer console in Chrome. I can see that there was a call out to save the preference when invoked, and confirmed that it had been set by calling getUserPref.

I've performed much the same test with Visual Studio 2013 by previewing the app and running the commands from the JS Console with the same results.

Is there something I'm missing here?

回答1:

I found that calling the connect after authenticating and before getting the preferences, i.e.:

WL.Cient.connect({onSuccess:successFunction, onFailure:failureFunction});
var myPref = WL.Client.getUserPref("myPref");

This should do the trick.