Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application is open, but Won't go to callback #4

Open
odedBartov opened this issue Jun 18, 2021 · 15 comments
Open

Application is open, but Won't go to callback #4

odedBartov opened this issue Jun 18, 2021 · 15 comments

Comments

@odedBartov
Copy link

odedBartov commented Jun 18, 2021

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

@udit2910
Copy link

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.

@deni-begaj
Copy link

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

@arsentabaku
Copy link

arsentabaku commented Jun 25, 2021

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.

@deni-begaj
Copy link

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

@gerardim90
Copy link

gerardim90 commented Jun 30, 2021

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

@OPADA-Eng
Copy link

Any progress on this?

@keerl
Copy link
Contributor

keerl commented Dec 15, 2021

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.

@kefahB
Copy link
Contributor

kefahB commented Jan 14, 2022

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.

@NathanWalker
Copy link
Member

NathanWalker commented Jan 18, 2022

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

@keerl
Copy link
Contributor

keerl commented Jan 19, 2022

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?

@NathanWalker
Copy link
Member

NathanWalker commented Jan 19, 2022

Further context can be seen in this discussion (bit older but still relevant):
BranchMetrics/ios-branch-deep-linking-attribution#277 (comment)

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.

@Bezlepkin
Copy link

Bezlepkin commented Feb 9, 2022

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) { } });

@lukBB
Copy link

lukBB commented May 21, 2022

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

@kefahB
Copy link
Contributor

kefahB commented Nov 20, 2022

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
Copy link
Contributor

kefahB commented Nov 20, 2022

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
    });
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests