在NativeScript中访问iOS通用链接中的查询参数 [英] Access query parameters in iOS universal links in NativeScript
问题描述
问题:如何使用urlhandler插件从NativeScript应用中的iOS通用链接访问查询参数(例如?id = bogus& time = now)?
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?
我正在开发一个包含nativescript-urlhandler插件的javascript NativeScript应用程序.我需要能够通过短信接收深层链接,打开应用程序,并访问链接的完整URL.这在Android上运行正常,但在iOS上却无法正常运行.
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.
在iOS上,深层链接会打开应用程序,但不会触发handleOpenURL函数.我已经花了几个小时进行搜索,并且似乎似乎是url处理程序插件需要处理appDelegate的ContinueUserActivity.但是,我不知道该如何取得进展.
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.
相关参考文献:
https://medium.com/@abhimuralidharan/universal-links -in-ios-79c4ee038272
https://developerinsider.co/handle-query-parameters- in-universal-links/
我相信我在应用程序设置和apple-app-site-association文件方面拥有一切.就像我说的那样,深层链接确实会打开iOS应用程序,我只是无法获得可以访问链接上传递的数据的方式的控制权.
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.
推荐答案
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.
这是app.js中有问题的代码,它可能使我节省了三天的时间才能解决其他人的问题:
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;
}
这篇关于在NativeScript中访问iOS通用链接中的查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!