问题
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