0

I have a method in JavaScript that looks as follows:

function onAction() {
    getValue1();
    getValue2();
    getValue3();
}

When I call onAction() I see two different behaviors between Mobile Safari and Android Chrome. In Safari, I get the values for all three methods. On Android Chrome, I only get the value of the last method. It doesn't matter which one is last. I suspected it may be an execution timing issue and attempted the following:

function onAction() {

    new Promise(function(resolve,reject) {
        resolve(1);
    })
    .then(function() {
        getValue1();
    })
    .then(function() {
        getValue2();
    })
    .then(function() {
        getValue3();
    });
}           

Again, it works fine in Mobile Safari, but not Android Chrome.

I'm sure I'm missing something obvious, but it's eluding me. If it matters, the getValue* functions are used to get values via each platform's mechanism for Native Code->JavaScript bridging.

Any help is appreciated. Please let me know if I can supply any more information.

Regards,
Rob

**Additional Info **
The getValueX functions don't return any values. They trigger values to be pushed over to the native wrapper:

function getReaderSDKVersion() {
    var message = {'action' : MPDataEnum.SDKVersion};
    raiseMessage(message);
}

function raiseMessage(message) {
    if (isPlatformiOS()) {
        window.webkit.messageHandlers.interOp.postMessage(message);
    } else {
        var url = "mpcard://runMethod#" + JSON.stringify(message);
        window.location.href = url;
    }
}
voodoobilly
  • 405
  • 7
  • 18

1 Answers1

0

The issue is answered here:

Triggering shouldStartLoadWithRequest with multiple window.location.href calls

Whereas this was an issue in most browsers, it doesn't appear to affect Mobile Safari now.

Community
  • 1
  • 1
voodoobilly
  • 405
  • 7
  • 18