Access query parameters in iOS universal links in NativeScript

岁酱吖の 提交于 2019-12-11 15:39:34

问题


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.


回答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;
} 



回答2:


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 ...



来源:https://stackoverflow.com/questions/51681898/access-query-parameters-in-ios-universal-links-in-nativescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!