react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

dynamicLinks().onLink() not getting called when app is freshly launched from link

Open HannanShaikYara opened this issue 6 years ago • 27 comments

Hello Guys,

I have integrated Firebase dynamic links with @react-native-firebase/dynamic-links version 6.3.4

const handleDynamicLink = async link => {
    console.log('***', link)
}

  useEffect(() => {
    const unsubscribe = dynamicLinks().onLink(handleDynamicLink)
    // When the is component unmounted, remove the listener
    return () => unsubscribe()
  })

The handleDynamicLink is called when the app is already in background.

However if the app is closed and freshly launched by tapping on the link it does not get called.

Please help.

package.json:

"@react-native-firebase/app": "^6.3.4",
"@react-native-firebase/dynamic-links": "^6.3.4",

HannanShaikYara avatar Mar 26 '20 12:03 HannanShaikYara

I have the same issue on Android (RNF 6.3.4). iOS not tested yet.

ahanusek avatar Mar 26 '20 14:03 ahanusek

Have you tried usage with getInitialLink? The onLink handler will only be called when the app is in the foreground.

Ehesp avatar Mar 26 '20 21:03 Ehesp

Have you tried usage with getInitialLink? The onLink handler will only be called when the app is in the foreground.

@Ehesp Oh my fault, getInitialLink works and returning a link. Sorry, I miss understood the documentation about this method.

ahanusek avatar Mar 27 '20 07:03 ahanusek

@Ehesp

Probably I found another issue connected with this feature. I have below flow in my app:

  1. The user gets an invitation with a dynamic link to the chat room on email
  2. Open the link and goes to the app, then App read the token from a link and processing registration to the chat room.

So when I'm testing this on Android (debug mode) the dynamic link from the first invitation works well, but when you open another invitation, getInitialLink method still returns link with the token from the first link. onLink method doesn't work too because every time I'm clicking on the link the app starts from scratch.

I'm missing something or should I generate not only a new token but the whole link should be different? Or maybe there is the way to clear the initial link?

ahanusek avatar Mar 31 '20 11:03 ahanusek

That seems like a bug with the initial link not getting removed once it's been consumed. Let me take a look, however it's probably worth creating a separate issue so we can track it.

Ehesp avatar Mar 31 '20 12:03 Ehesp

@Ehesp I found an old bug with a possible solution. I will check that and will return with feedback.

https://github.com/invertase/react-native-firebase/issues/2631

ahanusek avatar Mar 31 '20 12:03 ahanusek

Nope, I've added:

android:launchMode="singleTask"

to AndroidManifest but still, getInitialLink returns link from the first invitation.

ahanusek avatar Mar 31 '20 12:03 ahanusek

Yeah I don't think that would sort it, that's just how Android handles the activity when launching an intent.

Does it work on iOS?

Ehesp avatar Mar 31 '20 12:03 Ehesp

Can I test this feature without the deployed app to the App Store? I have the app only in TestFlight now.

ahanusek avatar Mar 31 '20 12:03 ahanusek

Yeah you can, we test on real devices with it just being installed from XCode.

Ehesp avatar Mar 31 '20 12:03 Ehesp

But when I'm trying open link (slack, email) on ma device (iPhone XS) iOS redirect me to the fallback page (website). I've added App Store ID, Bundle ID, and Team ID in the firebase console few days ago.

E: Oh, I forgot about this configuration for iOS https://youtu.be/KLBjAg6HvG0?t=407

ahanusek avatar Mar 31 '20 13:03 ahanusek

@Ehesp Ok, I got it, the app is opening after clicking on the link but it is even worse than on Android. getInitiaLink returns always null and onLink doesn't work too. 😢

ahanusek avatar Mar 31 '20 14:03 ahanusek

@ahanusek did you found any solution ?

thilinawarnakula avatar Jun 08 '20 10:06 thilinawarnakula

@thilinawarnakula Yes, I will try to share my solution later (today or tomorrow).

ahanusek avatar Jun 08 '20 11:06 ahanusek

@ahanusek Could you share your solution for iOS? I am having the same issue.

markus-utke avatar Jul 21 '20 19:07 markus-utke

@markuscosinus there are two separate methods to handle this. 1.App in Foreground events 2.App in Background/Quit events

thilinawarnakula avatar Jul 22 '20 04:07 thilinawarnakula

same issue happens for me. Backround/quit method works. Foregound method doesnt

adarshponaka avatar Jul 23 '20 16:07 adarshponaka

Can someone help on this? dynamicLinks() .getInitialLink() is working properly. but dynamicLinks() .onLink is not getting called when app is in foreground state. someone?

jyotishman avatar Aug 04 '20 11:08 jyotishman

+1..

Facing the same issues

RishavKumar-3796 avatar Sep 12 '20 07:09 RishavKumar-3796

@RishavKumar-3796 This is a closed issue. Please open a new issue following the issue template. Please make sure you are using up to date versions and still reproducing the problem

mikehardy avatar Sep 12 '20 14:09 mikehardy