-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handleOpenURL() does not seem to be triggered when cliking a link when the App is closed #2
Comments
Hi Oren, thanks! Let's see if we can tackle this.. are you refering to iOS or Android? And is it possible to have a look at your code? Maybe a github url, or a private mail to eddyverbruggen[at]gmail.com? |
Hi Eddy, So far testing on iOS (soon will test on Android). The code is very simple: function handleOpenURL(url) { However - please note that this function is defined inside an EXTERNAL JS file. |
Hi Oren, Yes, that could very well be the case! On iOS, the handleOpenURL is called from native code when the device is getting ready.. and that is likely to happen before any external content is loaded. Could you inline the function in your index.html and check if it fires? Thanks! |
Yes - will check ASAP. function handleOpenURL(url) { |
Not a bad idea and totally doable. However, the JS still needs to be triggered, so you know when to check for a (change to) the global variable. On coldstart you can have a startup check, but while running, you need to be triggered to check it. So indeed, a combination of these would work best: having the handleOpenURL function as it is now and being able to programmatically check a global variable (or a session variable). Thanks for the idea, I will keep this issue open as a reminder. |
I can confirm that if the handleOpenURL() function is placed in the index.html HEAD - then it's working as expected! |
Okay.. this is very weird. What happens for me is that only the first command inside the handleOpenURL() function gets triggered when the App launches for the first time. For example:
If your click a link (e.g. mycoolapp://something?key=value) and the App is CLOSED - the handleOpenURL() will do "alert(1)" and nothing else. Any ideas..? (tested on iOS7) Thanks, |
Hi, I don't have an iOS device on me these days, but I can imagine it works the way you describe. The iOS hook for this plugin is quite different from Android, and it seems part of the startup cycle of phonegap to invoke the javascript function. I guess it's some internal thingy we should not care too much about. Is it a problem in real code? I think you can do all the stuff you need to do and just don't alert anything anyway ;) |
The alert was just an example. But I need to keep drilling down into this to be sure. My problem is this: Even if I am right - and there is some weird issue with the function in iOS - I will find a workaround and post it here shortly. |
Okay - managed to find a workaround: I do not know why the 3 seconds delay is required.. so that's not a bullet-proof solution - but it works quite reliably on both Android and iOS. The following example shows how to wait for an external JS object to load (myAppObject) and once it exists - a myAppObject variable "target_url" is set so that it can then be used internally whenever required. The handleOpenURL() function MUST reside in the index.html of the local WWW folder:
myAppObject - handle_url() example:
Hope someone will find this useful :) |
Thanks Eddy for the awesome plugin and thanks Oren for sharing your experiences. I've tested the plugin on both iOS and Android, it works like a charm, on both iOS and Android it did seem like the app was always being relaunched with an url scheme click, however I didn't verify I think this plugin deserves more love, it might be a good idea to make the name more explanatory like "Custom URL Scheme" for it to be discovered better at Phonegap Plugins The reason I'm hijacking this issue is: It seems facebook is calling apps with a custom url scheme of it's own, would "LaunchMyApp" catch these urls too? |
Hi, @kaansoral Yes, I'm pretty sure those fb callbacks are caught by this plugin as well. @orenagiv Is the myAppObject function defined in an external or local JS file? Thanks guys!! |
Hey guys, Sorry for my extermely late response :) Only now noticed Eddy was asking a question... Better late than never :) Eddy - the myAppObject function in my example above is defined in an EXTERNAL JS file. |
Hi Eddy, |
The function handleOpenURL not called even I put in in the top of index.js. Even set the timeout with 4000 value, this function doesn't call also when the application is closed. |
Hi Eddy. Here it goes.
Hope this will improve the plugin. |
handleOpenURL is not firing but i am using a plugin https://github.com/code4jhon/org.apache.cordova.startapp to open the app from another cordova app would this prevent handleOpenURL to fire? |
got it working, was a permission issue when adding plugin ... some configs and files where not been added. Will try to make a post about this plugin used in Sencha Touch 2.3 / Cordova 3.5 apps. Regards. |
Cool thanks, and glad you figured it out before I found time to take a look 👍 |
I'm seeing the same behavior as other people. @Netpolice pretty much sums it up, the plugin works when the app is backgrounded, but the callback does not fire, despite being defined in the head of my index. I haven't dug too deep to investigate the cause, but the timeout fix that people are suggesting, seem like workarounds rather than best practice. @terikon you're post mentions that you have a solution that you hope can be merged, but I don't see a merge request. Do patches exist somewhere? |
I've added a state variable that simply stores the latest url. This is inspired by @aabilio's comment in #29 where he suggested storing the url in localstorage as a I still don't understand why |
@EddyVerbruggen I am running the latest version of cordova as of right now and have just recently uninstalled and reinstalled the launchmyapp plugin just to be safe. I have also read the entire thread and tried all relevant solutions. Issue: When a url launches the app on iOS from a coldstart (not running in the background) the handleOpenUrl() never fires. Ive tried putting it in the head and tried various ways of utilizing setTimeout. It works like a charm when the app is already in the background and it launches. I am able to grab the launch url and do what I need with it. This is how I was planning to implement. In the head or somewhere near the start of my index.html have this:
Then after my app has initialized, I would redefine the variable like so:
The problem still stands that I can't get the handleOpenUrl to fire at all when it is launched from cold. If it is worth noting, I am getting this in my console in Xcode:
Any help you could provide would definitely make my week at work go easier :) |
@84pennies Did you perhaps install the plugin manually? That console log indicates you have added the Android version of launchmyapp.js to your iOS project! |
@EddyVerbruggen Thanks so much for the quick reply! Really appreciate it. For reference, I am using one cordova project and I am not using phone gap build. I installed the plugin automatically using the cordova CLI command on the github readme. There seems to be a lot of contention amongst answers out there about what to put and not put in the config.xml when installing plugins in the current version of Cordova, so maybe something is amiss there? For the record, I currently don't have anything specific to your plugin in the config.xml (although I did have what was recommended in the readme at one point) and the behavior I am getting in iOS hasn't changed. I do still have everything in the androidmanifest.xml but I haven't tested on Android in a couple days. But still, I am a little miffed why it would be working when the app is already running if that had something to do with it. Do you have a recommended way of handling the different platforms when using one project? Right now there's only one www folder being used by both platforms (android and iOS) and it has the js file that is supposed to be used for Android. I suppose I could swap it out when i do builds but that seems cumbersome... Or I could manually copy it into the compiled www folder within the platform dir. But again... not the best it seems. Do you think this console error has something to do with the issue? I noticed that this plugin doesn't have a CDV file in Xcode anything to worry about there? |
@msalman That's not the Cordova-iOS version but the CLI version. Which Cordova-iOS version are you on? Problems arise with 3.7.0 and up. |
I use cordova -v to check the cordova version. In cordova lib project version file contains 3.7.0. cordova platform version ios sorry for being dumb, I am new to this. |
Yeah, 3.7.0 has the bug. Hopefully https://issues.apache.org/jira/browse/CB-7606 will be resolved in time for 3.8.0. |
Shazron has fixed the bug for 3.8.0 - I just tested it and it works fine :) |
Off topic, I recently inspected the cordova cli/platform versioning and how the cli handles platform libraries (mainly to write a tool to know when a new platform version is available and live) |
Hi. Yeah, Shazron explained how to do this in the apache issue mentioned above. See his test-steps. |
Thanks a lot for the pointer, it's very very helpful, After spending years hunting various mobile/cordova/webkit issues like these, it makes sense to just track https://git-wip-us.apache.org/repos/asf and add plugins/platforms manually when there are fixes that would take a long time to reach production, I'm even thinking of implementing a custom routine to parse for such changes and report them automatically / suggest utilising manual versions / upgrades |
I manually applied the fix into my Cordova iOS 3.7.0 project, because I was unable to upgrade to 3.8.0 via Note to my future self: once the Cordova iOS 3.8.0 is available via the command |
Cordova-ios 3.8.0 has just been released, including the fix for CB-7606. This should fix your trouble, thanks for the patience. |
@EddyVerbruggen I am using 3.8 now and |
Anyone looked at this approach ? |
@symbiat I like it |
I'm using the new PhoneGap Build version cli-5.1.1 and still experiencing this issue, on iOS. handleOpenURL fires nicely when app is in the background, but not lauching from cold start. |
@qkdreyer : Facing the same thing, have you managed to solve this? Thanks! |
Not yet sadly :/ |
Hi, I have used custom url plugin in my app and build it using phonegap build. <script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//alert("hello");
var delay = 3000; //Your delay in milliseconds
setTimeout(function(){
window.location = "home.html";
}, delay);
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the Cordova API
alert("device is ready");
function handleOpenURL(url) {
setTimeout(function() {
alert("received url: " + url);
}, 0);
}
}
});//end of document ready
</script>
//end of code
I have opened a url in my mobile browser(http://fornextit.com/south/test.html) and clicked on the link of my app. My app is opening however the url is not firing. Please help........ |
Cold Start Still not working for me. Using cordova CLI 5.1.1 and Cordova iOS version 3.8.0. Works fine in android and in iOS app running in background mode. When tried with cold start, app runs but handleOpenURL never fired. |
OK I fixed the issue for "Cordova CLI 5.1.1 - Cordova iOS version 3.8.0" by doing the following: Inside CDVHandleOpenURL.m: Changed
to
Then in Javascript code, introduced the following:
Hope this helps. |
@symbiat, great reference, thanks! |
@easym0de |
Hi, There function handleOpenURL(url) { function is not working. is any one here what should i do................. |
Hello Guy's, You can easily sort out this problem. In "CDVHandleOpenURL.m" file you need to change code as below NSString* jsString = [NSString stringWithFormat:@"document.addEventListener('deviceready',function(){if (typeof handleOpenURL === 'function') { handleOpenURL("%@");}});", url]; To NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL("%@");} else { window._savedOpenURL = "%@"; }", url, url]; this will work perfectly. Best of luck |
hola, si el plugin funciona bien en ambas plataformas.. pero, como hacer esto? |
Great work from @easym0de, this solution to update the cordova platform code solved the problem for me. What ways is there to package it into something that can be added to the git://git.apache.org/cordova-ios.git to make a more permanent solution? |
In my case the problem was solved after adding gap://ready to my Content-Security-Policy. I was wondering why safari gave me so many errors with gap://ready. so i added it, and it was solved. now handleOpenURL works as expected. |
How can i make a script that if anyone visits my website then his default home page is my websites URL |
None of these solutions work for me. Still having this issue in 2018. Navigating to a hosted login page, logging in which then redirects back to the app. Works fine in iOs emulator and android. Just not on actual ios device... |
Hi there,
The plugin seems to be working fantastic!
Once question though - The handleOpenURL(url) function does not seem to be triggered when clicking a link when the App is closed. It seems to work perfectly if the App is working in the background.
(Tested with PhoneGAP Build 3.1)
Thanks!
Oren.
The text was updated successfully, but these errors were encountered: