Closed GioviQ closed 8 years ago
Maybe when onDeviceReady is executed I should just know if the app is started because a link was clicked or not.
If I'm not mistaking, when app is read - you immediately redirect it to example.com. Because of that onRemotePageRequested
is not gonna be called: web page is different almost immediately after it's ready.
As a workaround you can try and add some timeout for redirecting to example.com:
var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function () {
universalLinks.subscribe(null, app.onRemotePageRequested);
app.redirectTimeoutID = setTimeout(function() {
window.location.replace("https://www.example.com");
}, 2000);
},
onRemotePageRequested: function (eventData) {
clearTimeout(app.redirectTimeoutID);
window.location.replace(eventData.url);
}
};
app.initialize();
universalLinks.subscribe(null, app.onRemotePageRequested)
sends request to the plugin to get notified, when default UL event occur. If app was launched from the link - onRemotePageRequested
will be called almost immediately. If not - when app was launched from the icon on the device. By setting timeout for redirect you give plugin some time to respond. 2sec might be too much, most likely it will take few milliseconds, but you will have to experiment with that.
thanks, for now I have seen it is called immediately
My index.js is
My cordova app is remote so window.location.replace redirect to remote site. When app is launched onDeviceReady executes before onRemotePageRequested (ok?) so do I always miss the universalLinks event, because www.example.com is currently loading / loaded? Thanks