IBM Worklight 6.0 - WL.Client.reloadApp() not work

2019-03-04 13:52发布

问题:

We are using Worklight 6.0.0 enterprise edition and currently building hybrid apps for android, BB, Windows Phone 8 and iOS.

We are currently getting the below error when invoking WL.Client.reloadApp() when clicking on a logout button. This works fine all OSs except for WP8.

CordovaBrowser_NavigationFailed :: ///www/default/www/default/pages/www/default/pages/www/default/pages/www/default/pages/myaccount.html ERROR: Exception in InvokeScriptCallback :: An unknown error has occurred. Error: 80020006. ERROR: Exception in InvokeScriptCallback :: An unknown error has occurred. Error: 80020006.

This is our logout function:

logout() {
    window.localStorage.clear();
    $.mobile.changePage("../MainPage.html");
    $('#username').val('');
    $('#password').val('');
    $("#Footer").show();
    $("#ui_logoutlst").hide();
    $("#homeBt_menu").hide();
    $('ul#QuickLinks li').width('50%');
};

回答1:

Updated April 8th, 2014

I have used the sample project you've provided in my previous answer.
Here's an updated version: WindowsTestApp

What I've done:

  1. Removed use of the path variable in wlCommonInit().

  2. Added the changeHash: false option to $.mobile.changePage().

    For example: $.mobile.changePage("Pages/MyAccount.html", { changeHash: false });

  3. In WindowTestApp.html

    Removed this line from the HEAD element:

    <script>window.$ = window.jQuery = WLJQ;</script>

  4. In js\jquery-1.10.2.js:

    Find

    xhr.open(s.type, s.url, s.async);

    Change to

    s.url = s.url.replace("x-wmapp0:///", "");
    xhr.open(s.type, s.url, s.async);


Step 3 is correct use of changePage in case of using WL.Client.reloadApp().

Step 4 seems to be a bug in jQuery/jQuery Mobile specific to handling to file location in Windows Phone.



回答2:

Looking at the edited comments and question, the problem could be at the path used.

Take a look at the multi-page sample project provided in the IBM Worklight Getting Started webpage. It contains special handling for WP8 which you may need to apply to your logout function as well.

Building a multi-page application training module
Multi-page sample project

  • See slides 8 and 9
  • Slide 8 talks about the implementation change below
  • Slide 9 talks about a change you must perform in jQuery Mobile's JS in order to make page navigation work.
  • Since you are using jQuery Mobile, take a look at this question and its answer: IBM Worklight v 5.0.6 - Can't navigate multipages on Windows Phone 7.5 environment

Note how the path is handled specifically for Windows Phone 8.
common\main.js:

var path = "";

function wlCommonInit(){
    // Special case for Windows Phone 8 only.
    if (WL.Client.getEnvironment() == WL.Environment.WINDOWS_PHONE_8) {
        path = "/www/default/";
    }
   ...
   ...
}

You need to now do one of two things:

  • account for the path for WP8
  • alter jQuery Mobile's JS if you use that