universal-links icon indicating copy to clipboard operation
universal-links copied to clipboard

Application is open, but Won't go to callback

Open odedBartov opened this issue 4 years ago • 15 comments

When the app is already opened in the background and i click the link its goes there with all the right details, but when the app is closed and i click the link the app will open, but as if i opened it regulary, without reaching the callback

odedBartov avatar Jun 18 '21 13:06 odedBartov

When thee app is already opened in the background and i cick the link its goes there with all the right details, but when the app is closed and i click the link the app will open, but as if i opened it regulary, without reaching the callback

I have been facing same issue. when app is open in background , everything works perfect but when we kill the app and tried to open from the link. it just opens the app but won't do the callback.

udit2910 avatar Jun 21 '21 10:06 udit2910

Same here, callback won't hit for iOS app. For Android works fine though.

deni-begaj avatar Jun 25 '21 08:06 deni-begaj

This is an error I was facing as well. My problem was related to a custom delegate we had created to handle a custom event not yet supported by Nativescript. Commenting out the custom delegate, actually fixed the issue and I can get the callback on iOS as well.

arsentabaku avatar Jun 25 '21 09:06 arsentabaku

Thanks for sharing that @ArsenTabaku will check my app for such custom events too.

deni-begaj avatar Jun 25 '21 09:06 deni-begaj

I am having the same error where my application opens from a universal link, but the function registerUniversalLinkCallback don't get executed on iOS... It happens opening the app from scratch or waking it up from the background. I am using Nativescript 6 and iOS 9+

ngOnInit(): void { registerUniversalLinkCallback( ul => { console.log(ul) alert(ul) })

@deni-begaj did you manage to get this working? Is there any angular application example someone could refrence? Thanks

gerardim90 avatar Jun 30 '21 04:06 gerardim90

Any progress on this?

OPADA-Eng avatar Oct 23 '21 15:10 OPADA-Eng

Could someone that has this issue send me a project that I can try to replicate the issue on? I tried to do it myself but I couldn't recreate the issue. It worked on iOS and Android even when the app was not previously open.

keerl avatar Dec 15 '21 03:12 keerl

Hi,

Did you try to declaring the registerUniversalLinkCallback at your app.ts ? then use it directly from there or use the getUniversalLink from other file if you have to wait for user authentication.

kefahB avatar Jan 14 '22 07:01 kefahB

@keerl I believe what's occurring here is in addition to applicationContinueUserActivityRestorationHandler on the iOS side, this should also be wired up to handle it for first launch as well:

addDelegateHandler(delegate, 'applicationOpenURLOptions', (app, url, options) => {
    let handled = false;
    if (url) {
        setUniversalLink(url.absoluteString);
        const callback = getRegisteredCallback();
        if (callback) {
            handled = true;
            callback(getUniversalLink());
        }
    }
    return handled;
})

Combined with the other delegate wiring, this would handle all scenarios better (first launch and resume).

NathanWalker avatar Jan 18 '22 22:01 NathanWalker

Thanks @NathanWalker ! I added your suggestion and published a new version 2.0.7. I have yet to encounter this issue though, it was always working for me on first launch and resume. Hopefully this fixes the issue everyone else seems to be having.

Could anyone that encountered this issue test the new version out and confirm it has been resolved?

keerl avatar Jan 19 '22 12:01 keerl

Further context can be seen in this discussion (bit older but still relevant): https://github.com/BranchMetrics/ios-branch-deep-linking-attribution/issues/277#issuecomment-171568208

Further comments in that thread the extra consideration if the app is using other delegates methods through other plugins - for example firebase modifies the app delegate as well, which is why having both delegate methods helps.

NathanWalker avatar Jan 19 '22 17:01 NathanWalker

Found a solution for Android and Angular. In main.ts registerUniversalLinkCallback(_ => {});

in app.component.ts

ngOnInit(): void { console.log(getUniversalLink()); }

it works when the application is launched fresh.

And for resume mode:

Application.on(Application.resumeEvent, function (args) { if (Application.android) { console.log(getUniversalLink()); } else if (Application.ios) { } });

Bezlepkin avatar Feb 09 '22 08:02 Bezlepkin

@Bezlepkin thanks for this, where did you put the code for resume mode, also in ngOnInit ?

lukBB avatar May 21 '22 14:05 lukBB

Hi,

I spending a little bit of time on this, the solution of @NathanWalker is really nice but still had some issue to populate the getUniversal Link when the delegate is manually set!

The work around is to user setUnivsealLink manually on the delegate



if (global.isIOS) {
	@NativeClass()
	@ObjCClass(UIApplicationDelegate)
	class UIApplicationDelegateImpl extends UIResponder implements UIApplicationDelegate {

	applicationContinueUserActivityRestorationHandler(application: UIApplication, userActivity: NSUserActivity, restorationHandler: (p1: NSArray<UIUserActivityRestoring>) => void): boolean {

            setUniversalLink(userActivity.webpageURL.absoluteString)
            console.error("getUniversalLink", getUniversalLink())
            return true;
         }

	applicationOpenURLOptions(app: UIApplication, url: NSURL, options: NSDictionary<string, any>): boolean {
                 console.error(">>>applicationOpenURLOptions")
                 console.error(url.absoluteString)
                  console.error("<<<applicationOpenURLOptions")

                  setUniversalLink(url.absoluteString)
	          return true; this is for Stripe
        }
        
        
    }

	Application.ios.delegate = UIApplicationDelegateImpl;
}

kefahB avatar Nov 20 '22 11:11 kefahB

Also it may help! I use the displayedEvent to handle the link when the app in the background of foreground state and I implement the registerUniversalLinkCallback on the landing page to handle the navigation when the app was closed and open again.

// app.ts
Application.on(Application.displayedEvent, (args) => {
    console.error("APP DESPLAYED EVENT");
    registerUniversalLinkCallback(link => {
        console.error("Link", link);
        // Handle the navigation
    });
})

kefahB avatar Nov 20 '22 11:11 kefahB