Apache Cordova
  1. Apache Cordova
  2. CB-7606

handleOpenURL handler firing more than necessary

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.5.0
    • Fix Version/s: 3.8.0
    • Component/s: iOS
    • Labels:
      None

      Description

      I'm not an Obj-C or Cordova programmer so bear with me.

      Let's say my app is running. Then I hop over to my mail app and click on a link (myapp://blahBlahBlah) that should open up my app. This works fine, the app opens, my own URL handler (in javascript) takes over, etc.

      However in Obj-C the view controller is – incorrectly, I believe – storing that scheme data (blahBlahBlah) in self.openURL (so that it can be picked up later in processOpenURL function, called during webView initialization).

      This isn't normally a problem, except when you move to a new page (window.href = "/new_page"), the webView initialization runs again and picks up the old (already-acted-upon) openURL variable. (it's then set to nil, so that it doesn't get acted upon a third time, fourth time, etc...).

      I might have some details wrong, but it should be fairly easy to walk through with a project-wide search for "openurl". Just seems like a slightly wrong logic-flow, which unfortunately is interfering with my app.

        Issue Links

          Activity

          Hide
          Maxime Boucher-Allard added a comment -

          I'm having the exact same issue in my project, handleOpenURL fires twice, the second time being when I move to a new page.

          Show
          Maxime Boucher-Allard added a comment - I'm having the exact same issue in my project, handleOpenURL fires twice, the second time being when I move to a new page.
          Hide
          Shazron Abdullah added a comment -

          I agree that this is annoying and should be fixed (besides causing other problems). Here's why it was done this way:

          1. app is not running (send event in AppDelegate, gets picked up in the view controller)
          2. app is running (set javascript in AppDelegate)

          Case (1) is when the WebView hasn't been created yet. The best solution is for the view controller to query the AppDelegate for any stored openURL call, then execute if available, then clear the stored openURL call.

          Show
          Shazron Abdullah added a comment - I agree that this is annoying and should be fixed (besides causing other problems). Here's why it was done this way: 1. app is not running (send event in AppDelegate, gets picked up in the view controller) 2. app is running (set javascript in AppDelegate) Case (1) is when the WebView hasn't been created yet. The best solution is for the view controller to query the AppDelegate for any stored openURL call, then execute if available, then clear the stored openURL call.
          Hide
          ASF subversion and git services added a comment -

          Commit 01b3d191d47b5f5b9549a1174b0d92ae0f0a901d in cordova-ios's branch refs/heads/master from Shazron Abdullah
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=01b3d19 ]

          CB-7606 - handleOpenURL handler firing more than necessary

          • plus style fixups through uncrustify
          Show
          ASF subversion and git services added a comment - Commit 01b3d191d47b5f5b9549a1174b0d92ae0f0a901d in cordova-ios's branch refs/heads/master from Shazron Abdullah [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=01b3d19 ] CB-7606 - handleOpenURL handler firing more than necessary plus style fixups through uncrustify
          Hide
          Shazron Abdullah added a comment -

          Tested launching through custom scheme:
          1. when app is running
          2. when app is not running
          3. when app is running, and navigate to another local page

          Show
          Shazron Abdullah added a comment - Tested launching through custom scheme: 1. when app is running 2. when app is not running 3. when app is running, and navigate to another local page
          Hide
          Eddy Verbruggen added a comment -

          Hi Shazron Abdullah,

          Thanks for picking this up, but I'm afraid it breaks a feature upon coldstart on iOS 8: my handleOpenURL function is no longer called. It was first reported here (tl;dr): https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/2

          So I was wondering how you tested case nr 2. Did iOS actually invoke your handelOpenURL javascript function? Because on my iPhone 6 it did on 3.6.3, but no longer on 3.7.0.

          I've altered the code in CDVViewController.m#processOpenUrl a bit to repair it on 3.7.0, but before submitting a PR I'd like to know if I'm testing this correctly.

          Thanks,
          Eddy

          Show
          Eddy Verbruggen added a comment - Hi Shazron Abdullah , Thanks for picking this up, but I'm afraid it breaks a feature upon coldstart on iOS 8: my handleOpenURL function is no longer called. It was first reported here (tl;dr): https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/2 So I was wondering how you tested case nr 2. Did iOS actually invoke your handelOpenURL javascript function? Because on my iPhone 6 it did on 3.6.3, but no longer on 3.7.0. I've altered the code in CDVViewController.m#processOpenUrl a bit to repair it on 3.7.0, but before submitting a PR I'd like to know if I'm testing this correctly. Thanks, Eddy
          Hide
          Benno Aichele added a comment - - edited

          We are also experiencing the problem, that handleOpenURL is no longer called upon coldstart.

          We are running on ios@3.7.0, cli version 4.0.0
          handleOpenURL when app is in background works still fine

          Eddy Verbruggen, could you share your patched CDVViewController.m#processOpenUrl somewhere?

          Show
          Benno Aichele added a comment - - edited We are also experiencing the problem, that handleOpenURL is no longer called upon coldstart. We are running on ios@3.7.0, cli version 4.0.0 handleOpenURL when app is in background works still fine Eddy Verbruggen , could you share your patched CDVViewController.m#processOpenUrl somewhere?
          Show
          Eddy Verbruggen added a comment - Benno Aichele sure, here you go: https://gist.github.com/EddyVerbruggen/3edb9f33b29d26c79ec7
          Hide
          Shazron Abdullah added a comment -

          I tested (2) by killing the app if running, and launching the custom url from Mobile Safari. I'll retest and verify, and look at your patch.

          Show
          Shazron Abdullah added a comment - I tested (2) by killing the app if running, and launching the custom url from Mobile Safari. I'll retest and verify, and look at your patch.
          Hide
          Paul Kane added a comment -

          I'm the original reporter of the issue. Although in JIRA I am no longer "watching" this issue I still receive an email for every update here. Can someone explain how to stop this?

          Show
          Paul Kane added a comment - I'm the original reporter of the issue. Although in JIRA I am no longer "watching" this issue I still receive an email for every update here. Can someone explain how to stop this?
          Hide
          Shazron Abdullah added a comment -
          Show
          Shazron Abdullah added a comment - You'll have to ask the Apache Admins, unfortunately by filing an INFRA issue: http://issues.apache.org/jira/browse/INFRA https://answers.atlassian.com/questions/77068/disable-auto-notifications-for-reporter
          Hide
          Paul Kane added a comment -

          Thanks for the info. Good to know I wasn't crazy (looked for it for quite a while). I'll just start sending these emails to my spam folder and let GMail sort it out.

          Show
          Paul Kane added a comment - Thanks for the info. Good to know I wasn't crazy (looked for it for quite a while). I'll just start sending these emails to my spam folder and let GMail sort it out.
          Hide
          Eddy Verbruggen added a comment -

          @shazron A few other guys (https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/56) have experienced cold start issues with 3.7.0, I really hope you can give this a second look soon.

          Cheers,
          Eddy

          Show
          Eddy Verbruggen added a comment - @shazron A few other guys ( https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/56 ) have experienced cold start issues with 3.7.0, I really hope you can give this a second look soon. Cheers, Eddy
          Hide
          Michael M added a comment -

          I tested both versions from here https://gist.github.com/EddyVerbruggen/3edb9f33b29d26c79ec7 The first one is not working and the second one does not work with warm start (i.e., the app is running in background).

          I use an iPhone 5 iOS 7.1.1.

          Show
          Michael M added a comment - I tested both versions from here https://gist.github.com/EddyVerbruggen/3edb9f33b29d26c79ec7 The first one is not working and the second one does not work with warm start (i.e., the app is running in background). I use an iPhone 5 iOS 7.1.1.
          Hide
          Jan Misker added a comment -

          I had a look at this and I think the call to handleOpenURL is injected too soon. It seems to be injected when the dom is ready, but at that point the JS that defines handleOpenURL might not have been evaluated.

          I made a quick fix for myself, which boils down to checking whether handleOpenURL exists, and if not assign the URL to a variable. Then I can check whether that variable is set, and if so call handleOpenURL with it.
          Not an ideal solution, but workable for me at the moment.
          Better would be if there is a trigger to CDViewController when the scripts on a page did evaluate, and inject the handleOpenURL call only after that trigger.

          See also here: https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/56#issuecomment-72113000

          Show
          Jan Misker added a comment - I had a look at this and I think the call to handleOpenURL is injected too soon. It seems to be injected when the dom is ready, but at that point the JS that defines handleOpenURL might not have been evaluated. I made a quick fix for myself, which boils down to checking whether handleOpenURL exists, and if not assign the URL to a variable. Then I can check whether that variable is set, and if so call handleOpenURL with it. Not an ideal solution, but workable for me at the moment. Better would be if there is a trigger to CDViewController when the scripts on a page did evaluate, and inject the handleOpenURL call only after that trigger. See also here: https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/56#issuecomment-72113000
          Hide
          Shazron Abdullah added a comment -

          Jan Misker Not sure how to have a "clean" implementation of this – setting it to a variable will work if you know what variable to use, but this will break current usage. I'm thinking whether just a delay in calling handleOpenURL will work (use a setTimeout for 1s or even less).

          Show
          Shazron Abdullah added a comment - Jan Misker Not sure how to have a "clean" implementation of this – setting it to a variable will work if you know what variable to use, but this will break current usage. I'm thinking whether just a delay in calling handleOpenURL will work (use a setTimeout for 1s or even less).
          Hide
          Shazron Abdullah added a comment -

          Took a look at Eddy's patch here: https://gist.github.com/EddyVerbruggen/3edb9f33b29d26c79ec7
          Looking at one of the comments, a fixed delay is still not optimal, because modern vs older devices will behave differently.

          Been trying to find the best solution that works in a deterministic way. Talking to Jesse MacFadyen - he thinks the best way to make this behave in a deterministic manner is to tie it to cordova's deviceready event, and I agree.

          NSString* jsString = [NSString stringWithFormat:@"document.addEventListener('deviceready',function(){if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}});", url];
          [webView stringByEvaluatingJavaScriptFromString:jsString];
          

          cordova duck-punches (no animals were hurt!) document.addEventListener to do what it needs to do, so because of this, if deviceready has already fired, the callback will fire right away – so handleOpenURL will always be called.

          I haven't tested this yet, but I will try this approach and report back. I'm also testing Antonio's approach here: https://issues.apache.org/jira/browse/CB-8028?focusedCommentId=14231236&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14231236
          .. he reports it as working, but this depends on plugins being loaded before the url is handled, so there might be timing issues there.

          Show
          Shazron Abdullah added a comment - Took a look at Eddy's patch here: https://gist.github.com/EddyVerbruggen/3edb9f33b29d26c79ec7 Looking at one of the comments, a fixed delay is still not optimal, because modern vs older devices will behave differently. Been trying to find the best solution that works in a deterministic way. Talking to Jesse MacFadyen - he thinks the best way to make this behave in a deterministic manner is to tie it to cordova's deviceready event, and I agree. NSString* jsString = [NSString stringWithFormat:@ "document.addEventListener('deviceready',function(){ if (typeof handleOpenURL === 'function') { handleOpenURL(\" %@\ ");}});" , url]; [webView stringByEvaluatingJavaScriptFromString:jsString]; cordova duck-punches (no animals were hurt!) document.addEventListener to do what it needs to do, so because of this, if deviceready has already fired, the callback will fire right away – so handleOpenURL will always be called. I haven't tested this yet, but I will try this approach and report back. I'm also testing Antonio's approach here: https://issues.apache.org/jira/browse/CB-8028?focusedCommentId=14231236&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14231236 .. he reports it as working, but this depends on plugins being loaded before the url is handled, so there might be timing issues there.
          Hide
          Shazron Abdullah added a comment -

          After doing tests, deviceready method works with a warm start, but never fires during a cold start (CB-8028).

          Show
          Shazron Abdullah added a comment - After doing tests, deviceready method works with a warm start, but never fires during a cold start ( CB-8028 ).
          Hide
          Shazron Abdullah added a comment -

          The plugin approach in CB-8028 works. So now to combine the two approaches so both cold and warm starts work.

          Show
          Shazron Abdullah added a comment - The plugin approach in CB-8028 works. So now to combine the two approaches so both cold and warm starts work.
          Hide
          Shazron Abdullah added a comment -

          I've solved this using the plugin approach, with some modifications. The processOpenURL code in CDVViewController has to be removed however, and it requires deleting a line in AppDelegate.m.

          I'll post the plugin and solution soon.

          Show
          Shazron Abdullah added a comment - I've solved this using the plugin approach, with some modifications. The processOpenURL code in CDVViewController has to be removed however, and it requires deleting a line in AppDelegate.m. I'll post the plugin and solution soon.
          Hide
          ASF subversion and git services added a comment -

          Commit 725293ad0187d6df55f3c8276982196c2a38ec4f in cordova-ios's branch refs/heads/CB-7606 from Shazron Abdullah
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=725293a ]

          CB-7606 - handleOpenURL not working correctly on cold start (handler not evaluated yet) and warm start

          Show
          ASF subversion and git services added a comment - Commit 725293ad0187d6df55f3c8276982196c2a38ec4f in cordova-ios's branch refs/heads/ CB-7606 from Shazron Abdullah [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=725293a ] CB-7606 - handleOpenURL not working correctly on cold start (handler not evaluated yet) and warm start
          Hide
          Shazron Abdullah added a comment - - edited

          Ok the fix is ready, in the CB-7606 branch. I've tested it using a cold and warm start. Instructions:

          cordova create CB-7606 cb.7606.test CB-7606
          cd CB-7606
          cordova platform add ios@CB-7606 --usegit
          open -a Xcode platforms/ios
          

          Add your URL handler in Info.plist (Open as Source Code, add within the <dict>):

                  <key>CFBundleURLTypes</key>
                  <array>
                      <dict>
                          <key>CFBundleURLName</key>
                          <string>myscheme</string>
                          <key>CFBundleURLSchemes</key>
                          <array>
                              <string>myscheme</string>
                          </array>
                      </dict>
                  </array>
          

          Edit your Scheme (click on the Target in the Xcode toolbar):

          1. Select the Launch Tab
          2. Select the Launch (Wait for Executable to be Launched) radio button
          

          Add this at the top of the Staging/www/js/index.js file in Xcode Project Navigator:

          function handleOpenURL(url) {
              setTimeout(function() {
                         alert(url);
                         }, 500);
          }
          

          To test:

          1. In Mobile Safari, enter the url "myscheme://" in the Location bar
          2. Select the "Go" button on the keyboard
          3. Wait until the app launches, and the alert should show
          4. Press the Home button
          5. Repeat Steps 1, 2 and 3 to now test warm start.
          

          Please test, let me know so I can land this in 3.8.0 and start the release process.

          Show
          Shazron Abdullah added a comment - - edited Ok the fix is ready, in the CB-7606 branch. I've tested it using a cold and warm start. Instructions: cordova create CB-7606 cb.7606.test CB-7606 cd CB-7606 cordova platform add ios@CB-7606 --usegit open -a Xcode platforms/ios Add your URL handler in Info.plist (Open as Source Code, add within the <dict>): <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>myscheme</string> <key>CFBundleURLSchemes</key> <array> <string>myscheme</string> </array> </dict> </array> Edit your Scheme (click on the Target in the Xcode toolbar): 1. Select the Launch Tab 2. Select the Launch (Wait for Executable to be Launched) radio button Add this at the top of the Staging/www/js/index.js file in Xcode Project Navigator: function handleOpenURL(url) { setTimeout(function() { alert(url); }, 500); } To test: 1. In Mobile Safari, enter the url "myscheme: //" in the Location bar 2. Select the "Go" button on the keyboard 3. Wait until the app launches, and the alert should show 4. Press the Home button 5. Repeat Steps 1, 2 and 3 to now test warm start. Please test, let me know so I can land this in 3.8.0 and start the release process.
          Hide
          Brian de Alwis added a comment -

          I applied this fix against 3.7.0 and it seems to have fixed the cold-start issues that I have been encountering. Thanks!

          Show
          Brian de Alwis added a comment - I applied this fix against 3.7.0 and it seems to have fixed the cold-start issues that I have been encountering. Thanks!
          Hide
          Shazron Abdullah added a comment -

          Alright, I've only gotten one piece of feedback (Brian de Alwis) regarding this fix. I'm going to proceed tomorrow on integrating, testing and releasing 3.8.0 based on my own tests. I can always patch the release branch if someone finds anything.

          Show
          Shazron Abdullah added a comment - Alright, I've only gotten one piece of feedback (Brian de Alwis) regarding this fix. I'm going to proceed tomorrow on integrating, testing and releasing 3.8.0 based on my own tests. I can always patch the release branch if someone finds anything.
          Hide
          ASF subversion and git services added a comment -

          Commit ed54ddf2cc6e2b746a406e15e99f549846cd171b in cordova-ios's branch refs/heads/master from Shazron Abdullah
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=ed54ddf ]

          CB-7606 - handleOpenURL not working correctly on cold start (handler not evaluated yet) and warm start

          Show
          ASF subversion and git services added a comment - Commit ed54ddf2cc6e2b746a406e15e99f549846cd171b in cordova-ios's branch refs/heads/master from Shazron Abdullah [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=ed54ddf ] CB-7606 - handleOpenURL not working correctly on cold start (handler not evaluated yet) and warm start
          Hide
          Eddy Verbruggen added a comment -

          Hi Shazron Abdullah, finally got around to test your fix - it works perfectly fine for me, thanks a lot!

          Eddy

          Show
          Eddy Verbruggen added a comment - Hi Shazron Abdullah , finally got around to test your fix - it works perfectly fine for me, thanks a lot! Eddy
          Hide
          Lauri Lehmijoki added a comment - - edited

          Thank you Shazron for the fix! I can confirm that it fixed the cordstart issue.

          However, I had to apply the patch manually, since Cordova iOS 3.8.0 is not available via the

          cordova platform update ios

          command.

          When will the version 3.8.0 be available to the command-line interface tools?

          Show
          Lauri Lehmijoki added a comment - - edited Thank you Shazron for the fix! I can confirm that it fixed the cordstart issue. However, I had to apply the patch manually , since Cordova iOS 3.8.0 is not available via the cordova platform update ios command. When will the version 3.8.0 be available to the command-line interface tools?
          Hide
          Chris Emerson added a comment - - edited

          Anyone else seeing the "cold start" issue return after/as-of the most recent version of Cordova? Hopefully I'm just screwing up the fix but it sure seems like it might be back. Because for me that timeout that Shazron posted in his fix is not firing on cold starts ... only after the app is opened.

          Show
          Chris Emerson added a comment - - edited Anyone else seeing the "cold start" issue return after/as-of the most recent version of Cordova? Hopefully I'm just screwing up the fix but it sure seems like it might be back. Because for me that timeout that Shazron posted in his fix is not firing on cold starts ... only after the app is opened.
          Hide
          Chris Emerson added a comment -

          Just an update ... I manually updated my Cordova files w/the updates here and that appears to fix the cold-start problem. When are these files going to be rolled into the current/latest Cordova version?

          Side/related question - When I run cordova --version I get 4.2 not 3.8 ... what am I missing/confusing here?

          Show
          Chris Emerson added a comment - Just an update ... I manually updated my Cordova files w/the updates here and that appears to fix the cold-start problem. When are these files going to be rolled into the current/latest Cordova version? Side/related question - When I run cordova --version I get 4.2 not 3.8 ... what am I missing/confusing here?
          Hide
          Shazron Abdullah added a comment -

          cordova-ios 3.8.0 is out [1], but is not in the tools release yet, we have to go through a separate voting process with that. The tools are versioned separately than the platform [2], so we can have independent platform releases now.

          1. http://cordova.apache.org/announcements/2015/02/25/cordova-ios-3.8.0.html
          2. http://cordova.apache.org/announcements/2014/10/16/cordova-4.html

          Show
          Shazron Abdullah added a comment - cordova-ios 3.8.0 is out [ 1 ], but is not in the tools release yet, we have to go through a separate voting process with that. The tools are versioned separately than the platform [ 2 ], so we can have independent platform releases now. 1. http://cordova.apache.org/announcements/2015/02/25/cordova-ios-3.8.0.html 2. http://cordova.apache.org/announcements/2014/10/16/cordova-4.html
          Hide
          Tom Cline added a comment -

          Shazron Abdullah

          Thanks for the patch! Unfortunately, I am still at a loss due to my ineptness or a conflict. Through the CLI I removed the ios platform, removed the shareURL plugin, and then proceeded to update cordova (4.2.0), add ios3.8 to the project, re-add the shareURL plugin, prepare the project, and build the project.

          Alas, I am now to a point where handleOpenURL never fires, cold or warm. I have repeated this process a few different times, in different sequences to the same end result. Any possible ideas where the conflict/issue could reside?

          I am also using, if it helps the following plugins (and have tested without wkwebview just to be safe, with the next steps being of testing on an empty project):

          device
          wkwebview
          media
          file
          socialsharing
          statusbar
          splashscreen
          inappbrowser

          Thanks for any help or direction you may be able to offer.

          Show
          Tom Cline added a comment - Shazron Abdullah Thanks for the patch! Unfortunately, I am still at a loss due to my ineptness or a conflict. Through the CLI I removed the ios platform, removed the shareURL plugin, and then proceeded to update cordova (4.2.0), add ios3.8 to the project, re-add the shareURL plugin, prepare the project, and build the project. Alas, I am now to a point where handleOpenURL never fires, cold or warm. I have repeated this process a few different times, in different sequences to the same end result. Any possible ideas where the conflict/issue could reside? I am also using, if it helps the following plugins (and have tested without wkwebview just to be safe, with the next steps being of testing on an empty project): device wkwebview media file socialsharing statusbar splashscreen inappbrowser Thanks for any help or direction you may be able to offer.
          Hide
          Sebastian Kellgren added a comment - - edited

          Shazron Abdullah, Awsome that you are looking in to this!

          But, seems like the fix for coldstart does not work for the ios@3.8.0.

          I have tried to recreate your test case from above and it's not running as expected. The warm start is firing the js handler as expected but not on the cold start. If i use version 3.6.0 everything fires as expected. I have also tried the exact steps as in your test branch and getting the CB-7606 branch with git. I don't know if this is related to a change in the tools or something else.

          I am very novice when it comes to ObjectiveC so i cant really tell you more in whats going on.

          My environment looks like this
          ~/code/CB-7606/CB-7606 master
          ❯ cordova -v
          4.2.0

          ❯ xcode -v
          Version 6.1.1 (6A2008a)

          The code that i've tried can be found here https://github.com/sekel/CB-7606.

          Edit: Any update on this?

          Show
          Sebastian Kellgren added a comment - - edited Shazron Abdullah , Awsome that you are looking in to this! But, seems like the fix for coldstart does not work for the ios@3.8.0. I have tried to recreate your test case from above and it's not running as expected. The warm start is firing the js handler as expected but not on the cold start. If i use version 3.6.0 everything fires as expected. I have also tried the exact steps as in your test branch and getting the CB-7606 branch with git. I don't know if this is related to a change in the tools or something else. I am very novice when it comes to ObjectiveC so i cant really tell you more in whats going on. My environment looks like this ~/code/ CB-7606 / CB-7606 master ❯ cordova -v 4.2.0 ❯ xcode -v Version 6.1.1 (6A2008a) The code that i've tried can be found here https://github.com/sekel/CB-7606 . Edit: Any update on this?
          Hide
          Shazron Abdullah added a comment - - edited

          I re-tested it using cordova-cli 4.3.0 which contains cordova-ios 3.8.0, and it is working with a cold start, and warm start.
          Here is my updated test case.

          cordova create CB7606 cb7606.test CB7606
          cd CB7606
          cordova platform add ios
          open -a Xcode platforms/ios
          

          Add your URL handler in Resources/Info.plist (Open as -> Source Code, add within the <dict> at the end):

                  <key>CFBundleURLTypes</key>
                  <array>
                      <dict>
                          <key>CFBundleURLName</key>
                          <string>myscheme</string>
                          <key>CFBundleURLSchemes</key>
                          <array>
                              <string>myscheme</string>
                          </array>
                      </dict>
                  </array>
          

          Add this at the top of the Staging/www/js/index.js file in Xcode Project Navigator:

          function handleOpenURL(url) {
              setTimeout(function() {
                         alert(url);
                         }, 500);
          }
          

          First we test warm start:
          1. Launch the app on device using Xcode
          2. Press the Home button to put the app in the background
          3. In Mobile Safari, enter the url "myscheme://warm" in the Location bar
          4. Select the "Go" button on the keyboard
          5. Wait until the app launches, and the alert should show

          Next we test cold start:
          1. Double press the Home button to show the app switcher (detach from Xcode first)
          2. Kill the CB7606 app by flipping the card upwards (might not be there if you detached from Xcode, if its not there that's good)
          3. In Mobile Safari, enter the url "myscheme://cold" in the Location bar
          4. Select the "Go" button on the keyboard
          5. Wait until the app launches, and the alert should show

          Show
          Shazron Abdullah added a comment - - edited I re-tested it using cordova-cli 4.3.0 which contains cordova-ios 3.8.0, and it is working with a cold start, and warm start. Here is my updated test case. cordova create CB7606 cb7606.test CB7606 cd CB7606 cordova platform add ios open -a Xcode platforms/ios Add your URL handler in Resources/Info.plist (Open as -> Source Code, add within the <dict> at the end): <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>myscheme</string> <key>CFBundleURLSchemes</key> <array> <string>myscheme</string> </array> </dict> </array> Add this at the top of the Staging/www/js/index.js file in Xcode Project Navigator: function handleOpenURL(url) { setTimeout(function() { alert(url); }, 500); } First we test warm start: 1. Launch the app on device using Xcode 2. Press the Home button to put the app in the background 3. In Mobile Safari, enter the url "myscheme://warm" in the Location bar 4. Select the "Go" button on the keyboard 5. Wait until the app launches, and the alert should show Next we test cold start: 1. Double press the Home button to show the app switcher (detach from Xcode first) 2. Kill the CB7606 app by flipping the card upwards (might not be there if you detached from Xcode, if its not there that's good) 3. In Mobile Safari, enter the url "myscheme://cold" in the Location bar 4. Select the "Go" button on the keyboard 5. Wait until the app launches, and the alert should show
          Hide
          Alan Casagrande added a comment -

          Here handleOpenURL is never called on 3.8.0 following your example. When I revert to 3.6.0, everything works. I'm using just the emulator to test.

          Not sure if I should create another issue?

          Show
          Alan Casagrande added a comment - Here handleOpenURL is never called on 3.8.0 following your example. When I revert to 3.6.0, everything works. I'm using just the emulator to test. Not sure if I should create another issue?
          Hide
          Shazron Abdullah added a comment -

          Why would you create another issue? Keep replying to this one. I've already tested this as I said, and it 100% absolutely works. This might just be user error on your part, most likely.

          Show
          Shazron Abdullah added a comment - Why would you create another issue? Keep replying to this one. I've already tested this as I said, and it 100% absolutely works. This might just be user error on your part, most likely.
          Hide
          Alan Casagrande added a comment - - edited

          This issue is named "handleOpenURL handler firing more than necessary" and it is resolved.

          The problem I'm reporting is that handleOpenURL is not called at all. That's why I would create another issue.

          This is what I did:

          1. Added cordova ios 3.8.0
          2. Strictly followed your example. App is invoked but alert is not displayed
          3. Completely removed cordova ios
          4. Added cordova ios 3.6.0
          5. Didn't touch my code
          6. Followed your example again. App is invoked and alert is displayed
          7. Completely removed cordova ios
          8. Added cordova ios 3.8.0
          9. Followed your example again. Alert is not displayed anymore

          So yes, it might be an error on my end, but it also might a problem with 3.8.0

          Show
          Alan Casagrande added a comment - - edited This issue is named "handleOpenURL handler firing more than necessary" and it is resolved. The problem I'm reporting is that handleOpenURL is not called at all. That's why I would create another issue. This is what I did: 1. Added cordova ios 3.8.0 2. Strictly followed your example. App is invoked but alert is not displayed 3. Completely removed cordova ios 4. Added cordova ios 3.6.0 5. Didn't touch my code 6. Followed your example again. App is invoked and alert is displayed 7. Completely removed cordova ios 8. Added cordova ios 3.8.0 9. Followed your example again. Alert is not displayed anymore So yes, it might be an error on my end, but it also might a problem with 3.8.0
          Hide
          Shazron Abdullah added a comment -

          Post your example code somewhere so I can take a look (without the 3.6.0 part)

          Show
          Shazron Abdullah added a comment - Post your example code somewhere so I can take a look (without the 3.6.0 part)
          Hide
          Shazron Abdullah added a comment -

          I re-tried my test case (again) and it still works. This time I come bearing gifts. Here is the project I used, uploaded to Github: https://github.com/shazron/CB-7606

          You can use this to run the project to see if it works for you and also view the source to see if yours is any different.

          Show
          Shazron Abdullah added a comment - I re-tried my test case (again) and it still works. This time I come bearing gifts. Here is the project I used, uploaded to Github: https://github.com/shazron/CB-7606 You can use this to run the project to see if it works for you and also view the source to see if yours is any different.
          Show
          Shazron Abdullah added a comment - Code changes: 1. https://github.com/shazron/CB-7606/blob/c0afef8e63a0631e6d0d4931cb24b6e0b4d8e4a1/platforms/ios/www/js/index.js#L20-L24 2. https://github.com/shazron/CB-7606/blob/c0afef8e63a0631e6d0d4931cb24b6e0b4d8e4a1/platforms/ios/CB7606/CB7606-Info.plist#L181-L191
          Hide
          Alan Casagrande added a comment -

          Thanks for posting your example, it worked here.

          I tested my original project again and still only works with 3.6.0, even though I'm using the latest cordova version. I suspect some cordova plugin might be interfering, I'll investigate more. Sorry for wasting your time.

          Show
          Alan Casagrande added a comment - Thanks for posting your example, it worked here. I tested my original project again and still only works with 3.6.0, even though I'm using the latest cordova version. I suspect some cordova plugin might be interfering, I'll investigate more. Sorry for wasting your time.
          Hide
          Tom Cline added a comment -

          Alan,

          I believe I am in the same boat as you are. I have been putting off
          debugging which plugin but if I do figure it out, I will let you know! If
          you happen to debug which plugin is in conflict, could you please share you
          findings here?

          Good luck!
          On Wed, Mar 25, 2015 at 4:52 PM Alan Casagrande (JIRA) <jira@apache.org>

          Show
          Tom Cline added a comment - Alan, I believe I am in the same boat as you are. I have been putting off debugging which plugin but if I do figure it out, I will let you know! If you happen to debug which plugin is in conflict, could you please share you findings here? Good luck! On Wed, Mar 25, 2015 at 4:52 PM Alan Casagrande (JIRA) <jira@apache.org>
          Hide
          Alan Casagrande added a comment -

          In the end I just removed all plugins and tested with https://github.com/EddyVerbruggen/Custom-URL-scheme only, it worked.

          Then I reinstalled the other plugins and it worked as well. So I guess it was an outdated plugin, but I don't know which one.

          If you are testing with an alert, it is important to use setTimeout. The app was freezing on the splash screen without it.

          Show
          Alan Casagrande added a comment - In the end I just removed all plugins and tested with https://github.com/EddyVerbruggen/Custom-URL-scheme only, it worked. Then I reinstalled the other plugins and it worked as well. So I guess it was an outdated plugin, but I don't know which one. If you are testing with an alert, it is important to use setTimeout. The app was freezing on the splash screen without it.

            People

            • Assignee:
              Shazron Abdullah
              Reporter:
              Paul Kane
            • Votes:
              5 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development