0

Question: how to access query parameters (e.g., ?id=bogus&time=now ) from a universal link on iOS in a NativeScript app using the urlhandler plugin?

I'm developing a javascript NativeScript app that includes the nativescript-urlhandler plug-in. I need to be able receive a deep-link via sms, open the app, and access the full url of the link. This works fine on Android, but not on iOS.

on iOS, the deep link opens the app, but does not trigger the handleOpenURL function. I've done several hours of searching on this, and it appears that the url handler plug-in needs to handle appDelegate's ContinueUserActivity. But, I don't know how to make progress.

Pertinent references:

https://medium.com/@abhimuralidharan/universal-links-in-ios-79c4ee038272

https://developerinsider.co/handle-query-parameters-in-universal-links/

iOS Universal Links and GET parameters

I believe I have everything in place in terms of the app's settings and the apple-app-site-association file. As I said, the deep link DOES open the iOS app, I'm just not getting control in such a way that I can access the data passed on the link.

I'd REALLY appreciate any insight or pointers.

David
  • 578
  • 3
  • 16

2 Answers2

1

I was ultimately able to get this working by specifying a custom UIApplicationDelegate for continueUserActivity, as per the {N} doc, without having to modify the urlhandler plugin.

Here's the code in question, in app.js, which may save someone else the three days it took me to figure this out:

const handleOpenURL = require("nativescript-urlhandler").handleOpenURL;

// Handle entry via deep-link URL via nativescript-urlhandler plugin 
handleOpenURL(function (appUrl) {
  console.log('handleOpenURL: ', appUrl.toString());
  routeUrl(appUrl.toString());
}); // end handleOpenURL

// Handle entry via universal link on iOS 
// See https://docs.nativescript.org/core-concepts/application-lifecycle#ios-uiapplicationdelegate 
// See https://medium.com/@abhimuralidharan/universal-links-in-ios-79c4ee038272
if (!global.isAndroid) {
  const MyDelegate = (function (_super) {
    __extends(MyDelegate, _super);
    function MyDelegate() {
      _super.apply(this, arguments);
    }
    MyDelegate.prototype.applicationContinueUserActivityRestorationHandler = function (application, userActivity) {
      if (userActivity.activityType === NSUserActivityTypeBrowsingWeb) {
        routeUrl(userActivity.webpageURL);
      }
      return true;
    };
    MyDelegate.ObjCProtocols = [UIApplicationDelegate];
    return MyDelegate;
  })(UIResponder);
  application.ios.delegate = MyDelegate;
} 
David
  • 578
  • 3
  • 16
  • I am attempting to do something similar: set up a universal link for my nativescript app, and then have that link opened and parsed via text message. Do you have code for how you set up the universal link in nativescript? – SeanRtS Sep 04 '19 at 18:23
  • @9gt53wS- there are a lot of moving parts here. You can google "iOS universal links " and find the Apple doc, but probably the best resource I used was https://blog.branch.io/how-to-setup-universal-links-to-deep-link-on-apple-ios/. – David Sep 04 '19 at 21:35
  • Thank you @David. That is a helpful source. The trickiest part seems to be to associate the Apple App Site Association ("AASA") file with my domain. The instructions seem to assume that you fully control the code of your website (basically assuming you have a web app in addition to your app). This is clear in their instructions that you add a json file in "your sites" root directory. BUT, in my current case (like many, I think), I don't have a separate website that i have built in addition to my app. – SeanRtS Sep 06 '19 at 14:05
  • I would like to just have the link either (i) send users to the app or (ii) send users to the app store listing (not a website I control) if they don't have the app already. I think that is the standard goal of developers, but I don't see instructions on how to do this. – SeanRtS Sep 06 '19 at 14:08
  • @9gt53wS I ended up adding a web subdomain to match that of the app. There's really not much there except the association files for Android and iOS. I also created a simple index.html file there so the link in the text message would resolve to something meaningful for the preview. If you don't have any access to the web site then I'm not sure that universal links will work for you. – David Sep 06 '19 at 17:34
  • David, can you please provide the full file, including what imports you used. I have gotten a domain set up for universal links, and have them working. But now I am trying to not only open the app from the link but have the app read the link and parse it. Like you were able to do. Haven't gotten it working yet. Tried your file, but getting errors, and it could be bc my imports are not correct. – SeanRtS Sep 21 '19 at 19:36
  • @gt53ws I added the surrounding code to the answer. The routeUrl function receives the full url, parses to, creates a viewModel, and then navigates to the target page via standard {N} frame navigation. Hope this helps. – David Sep 22 '19 at 21:47
  • Thanks, David. The use of "_extends" and "routeUrL" both cause errors for me. I think its bc I am using angular not vanilla js. I have posted a separate question on it: https://stackoverflow.com/questions/58062553/parse-ios-universal-links-with-nativescript-angular – SeanRtS Sep 23 '19 at 12:36
0

I've merged your changes here: https://jenkins.martinreinhardt-online.de/blue/organizations/jenkins/NPM%2Fnativescript-urlhandler/detail/develop/100/pipeline

Feel free to raise issues on GitHub at https://github.com/hypery2k/nativescript-urlhandler instead of sending emails ...

hypery2k
  • 1,681
  • 15
  • 20
  • currently nativescript-urlhandler v1.2.3 supports universal linking? I have tried but `handleOpenURL` function not calling however app open on link click. – Rakesh Sojitra Mar 15 '19 at 07:33