Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Event is not dispatched on the cold start #3

Closed
nikDemyankov opened this issue Sep 30, 2015 · 10 comments
Closed

Event is not dispatched on the cold start #3

nikDemyankov opened this issue Sep 30, 2015 · 10 comments
Labels

Comments

@nikDemyankov
Copy link
Member

If you launch the application first from the app icon, close it (by pressing home button on the phone) and then click on the UL link - JS event is captured.

But if you kill the app from task manager, and then click on the link - event is missed.

@rispig
Copy link

rispig commented Oct 1, 2015

Actually
it does work, you can close this @nikDemyankov
I was registering to the js event at the wrong time (inside device ready)

@nikDemyankov
Copy link
Member Author

With pleasure :)

@H0rst
Copy link

H0rst commented Nov 25, 2015

I still have this problem. I have a long index.html (old app) and have tried to add the event listener direct in a script part in the page and also in the onLoad event. In both cases the UL link event is fired when the app is already loaded in the background. When i kill it and try again, the app opens, but without the event.
I am trying with Android.
Any idea?

@nikDemyankov
Copy link
Member Author

Can you show some code, how you do the subscription and where?

@nikDemyankov nikDemyankov reopened this Nov 26, 2015
@H0rst
Copy link

H0rst commented Nov 26, 2015

I have made some tests. As i wrote, it is an old and big app. It has one big index.html. I include the cordova.ja and 33 other scripts at the beginning. After that i had this code:

<script> 
function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
        console.log('deviceready');
        document.addEventListener("resume", doResumeApp, false);
        document.addEventListener("pause", doPauseApp, false);         
        document.addEventListener("online", onOnline, false);         
        document.addEventListener("offline", onOffline, false);         
        console.log('eventhandler installed')
        Init(); 
};
function onULOpen(event) {
    alert('onULOpen');
}
document.addEventListener('ULOpen', onULOpen, false);

</script>

It has not worked, when the app was not running in the background. Now i have moved the UL block between the include of cordova.js and the other scripts.

<script> 
document.addEventListener('ULOpen', onULOpen, false);
function onULOpen(event) {
    alert('onULOpen');
}
</script>

And this works.
I have tested with a Samsung Galaxy Note 4.

@nikDemyankov
Copy link
Member Author

So now it's fine?

@H0rst
Copy link

H0rst commented Nov 26, 2015

Yes. I have now the event in front before loading other scripts.

Is it possible that the event is fired before the page is loaded?

Maybe you should add some information, when the event is called. In my tests i see it before resume and before deviceReady.

@nikDemyankov
Copy link
Member Author

When app is launched from the link - event is saved until plugins JS module is initialised. And this can happen before the deviceready in the index page. So, you need to subscribe to the event as soon as possible.

As a workaround I can add to the plugin JS module (i.e., universalLinks), and people can use it like so:

function onDeviceReady() {
  console.log('deviceready');

  // set handler for the event
  universalLinks.on('event_name', onULOpen);
};

function onULOpen(event) {
  // handle the event
}

Internally, it will store the events, received from the native side; and then universalLinks.on(...) is called - send them to the callback. Basically, you are subscribing to the event through the plugins module.

What do you think about that?

@H0rst
Copy link

H0rst commented Nov 26, 2015

This would be a good solution, because in the event all cordova stuff is available, when it is called after deviceReady.
This also prevents for timing issues.

PS: Thank you for your work.

@nikDemyankov
Copy link
Member Author

Thanks) Closing this issue. Created a separate one with the required feature.

dreusel pushed a commit to olisto/cordova-universal-links-plugin that referenced this issue Jul 31, 2018
backwards compatibility for AndroidManifest.xml changes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants