Closed dimitriospafos closed 4 years ago
Yeah, I was afraid something like this might happend, but could never reproduce in my own project. Here's what you could try: go edit the code in
node_modules/nativescript-plugin-universal-links/build/plugin-universal-links.common.js
Inside the registerUniversalLinkCallback
function body, put this code:
function registerUniversalLinkCallback(cb) {
callback = cb; // this was already there
if (universalLink) cb(universalLink); // add this
}
Rebuild your project and test. I think this could happen if the universal link gets parsed before the callback is registered.
@sebestindragos the above line of code does not seem to make any difference for me. registerUniversalLinkCallback is not being invoked even though the app opens.
I also tried to check "ul" in below code after the app opens from clicking on a link but I get undefined back. const ul = getUniversalLink();
Is there anything else that can be causing this? My iphone is on 13.4.1 btw
@dimitriospafos I think one of your other plugins might be replacing the application delegate. Could you make sure the universal link plugin is imported/required last? It has support for working with an existing delegate.
@sebestindragos I have a custom ios delegate assigned in main.ts which I guess overwrites the delegate that your plugin is initializing. I tried removing my custom delegate which fixed the above issue.
My custom delegate assignment in main.ts:
import * as application from "tns-core-modules/application";
...
class BackgroundAppDelegate extends UIResponder implements UIApplicationDelegate {
public static ObjCProtocols = [UIApplicationDelegate];
public applicationPerformFetchWithCompletionHandler(application: UIApplication, completionHandler: any) {
...
}
public applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary<string, any>): boolean {
…
}
}
application.ios.delegate = BackgroundAppDelegate;
The idea of the custom delegate is from: https://docs.nativescript.org/core-concepts/ios-runtime/how-to/BackgroundExecution
How can I make this work with your plugin? The custom delegate needs to be assigned before your plugin initializes the delegate, but I can't think of a way to do this at the moment. Any help would be appreciated here. Thanks
@dimitriospafos Try extracting your custom delegate in a separate file and in main.ts first you load that and then the universal links plugin
import './myBackgroundRunDelegate';
import {} from 'nativescript-plugin-universal-links';
@sebestindragos Tried that, doesn't work. I think the issue is that when I assign the custom background delegate like this : "application.ios.delegate = BackgroundAppDelegate; " after the imports it will overwrite the one from your plugin.
@dimitriospafos you're doing it wrong. Put your entire code in that file, even the assignment
// myBackgroundRunDelegate.ts
import * as application from "tns-core-modules/application";
...
class BackgroundAppDelegate extends UIResponder implements UIApplicationDelegate {
}
application.ios.delegate = BackgroundAppDelegate; // the assignment is done here, not in main.ts
and in main.ts
// this will import the file which will assign the background delegate
// notice there is no import * as bgDeletegate, just import /file/path
import './myBackgroundRunDelegate';
// this will load the universal plugin which will overwrite your custom delegate
import { registerUniversalLinkCallback } from 'nativescript-plugin-universal-links';
// do something with the universal link
registerUniversalLinkCallback(ul => {
...
});
@sebestindragos I tried the above still didn't work. Only it works is if I don't assign my custom delegate. I'm guessing the import statements might not be in order? At this point I'll rather implement the ios event: applicationContinueUserActivityRestorationHandler?(application: UIApplication, userActivity: NSUserActivity, restorationHandler: (p1: NSArray<UIUserActivityRestoring>) => void): boolean;
myself without using the plugin. I appreciate taking time to help me here. Thank you.
@dimitriospafos Well, feel free to use the source code from the plugin. You'll have to also do it for Android.
I added the AASA file to my root dir and validated it which looks good. I added the associated domain via Xcode.
The app launches correctly when i tap on a link, but registerUniversalLinkCallback is not being invoked. I tried setting a breakpoint on the console.log line below in the app.component.ts and it never gets hit and I don't see any logs in the output
package.json:
entitlements file:
app.component.ts :