Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23896] iOS: Add Ti.App.iOS "handleurl" event to handle incoming URL schemes

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-09-13T00:01:12.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.5.0
ComponentsiOS
Labelsn/a
ReporterHans Knöchel
AssigneeHans Knöchel
Created2016-09-12T17:02:30.000+0000
Updated2016-09-14T22:14:33.000+0000

Description

We should be able to get notified when a new URL scheme is handled by the application delegate.

Comments

  1. Hans Knöchel 2016-09-12

    Will be fixed as part of TIMOB-23890 and also provides a solution for TIMOB-23884.
  2. Hans Knöchel 2016-09-12

    Demo-code: https://gist.github.com/hansemannn/d2263475b40469d3f2e4b82f03cc345c
  3. Chee Kiat Ng 2016-09-12

    Updated the sample code here:
       var safari = require('ti.safaridialog');
       
       var win = Ti.UI.createWindow({
           backgroundColor: 'white'
       })
       
       var btn = Ti.UI.createButton({
           title: "Open safari dialog"
       });
       
       btn.addEventListener("click", function() {
           safari.open({
               url:"http://hans-knoechel.de/TIMOB-23884.php",
               title:"Hello World"
           });
       });
       
       Ti.App.iOS.addEventListener("handleurl", function(e) {
           // If the handled url is provided by the safari-dialog, close it (use-case for OAuth)
           if (e.launchOptions.source == "com.apple.SafariViewService") {
               safari.close();
           }
       });
       
       win.add(btn);
       win.open();
       
    [~hansknoechel] But when i click on "Open Test App", I get "Safari cannot open the page because the address is invalid". Not sure what to expect here?
  4. Hans Knöchel 2016-09-12

    Your tiapp.xml must be able to handle the url-scheme safaritest://, so you need the following in there:
       <ios>
           <plist>
             <dict>
               <key>CFBundleURLTypes</key>
               <array>
                 <dict>
                   <key>CFBundleURLName</key>
                   <string>com.appc.safaridialogtest</string>
                   <key>CFBundleURLSchemes</key>
                   <array>
                     <string>safaritest</string>
                   </array>
                 </dict>
               </array>
             </dict>
           </plist>
       </ios>
       
  5. Chee Kiat Ng 2016-09-13

    APPROVED. CR and FT passed.
  6. Christy Thomas 2016-09-13

    Would this be available to test via a nightly build? If so which one? I gave 5.5.0.v20160913000746 a try this morning and I'm not getting the handleurl event. Will this require more than just using the right SDK?
  7. Hans Knöchel 2016-09-13

    It's there. Use the following event:
       Ti.App.iOS.addEventListener("handleurl", function(e) {
           // If the handled url is provided by the safari-dialog, close it (use-case for OAuth)
           if (e.launchOptions.source == "com.apple.SafariViewService") {
               safari.close();
           }
       });
       
    Just checked the build-server as well, just to be sure. Also check that you selected the correct SDK version in your tiapp.xml.
  8. Christy Thomas 2016-09-13

    It worked. Thank you. I was missing the iOS part.
  9. Eric Wieber 2016-09-14

    Verified fixed, using: MacOS 10.12 (16A313a) Studio 4.7.1.201609100950 Ti SDK 5.5.0.GA Appc NPM 4.2.7 Appc CLI 5.5.0 Alloy 1.9.2 Xcode 8.0 (8A218a) handleurl event is fired and correctly handled. Tested using the provided test code as well as modified versions of it. The event was fired and caught properly.

JSON Source