Expo deeplinking issue with addEventListener

Using create-react-native-app with expo. The app is not ejected.

I use the following event handlers on a componentDidMount() on the entry file of the application.

    Linking.addEventListener('url', this.handleEvent)
    Linking.getInitialURL().then(url => this.handleUrl(url))

The expo URL structure i’m testing in development is - exp://mb-6uw.EXPO_ACCOUNT.PROJECT_NAME.exp.direct/+/QUERY_STRING

The initial URL handler works correctly and the query string can be processed. However the addEventListener call is not being called at all when the app is already open and a deep link is used.

https://docs.expo.io/versions/latest/guides/linking.html - There is no setup requirements in the linking page so the event listener should be working.

Are there any setup requirements or approaches to resolve this issue?

1 Like

Hi @georgelovegrove - could you possibly share a minimal example that repros this?

Additionally, it’s worth noting that the callback for Linking.addEventListener('url', this.handleEvent) receives an event and not a url string directly. To get the url from that you will need to do event.url. So, instead you can do Linking.addEventListener('url', ({ url }) => this.handleEvent(url))

3 Likes

Hey Brent,

Yeh expecting an event like in the docs. I’ve made a repo updating the graphcool example using expo, I have an auth component like this - https://github.com/georgelovegrove/graphcool-expo-auth0/blob/master/src/auth/auth.js

I have an entry file in the application i’m building that has the same event handlers.

The auth0 example part works - if I open a link with the web browser in expo then the redirect back from auth0 can be returned with the token.

However what i’m trying to do now is either open from the clipboard in expo or enter the URL into a browser and it opens the app with that information whilst the app is already open rather than a redirect from an expo browser thats been opened in-app. Only works when the app is closed and the app is then opened with the initialUrl.

Great work on expo btw!

Have you found any solution? I’m deling with the same problem. Android is working fine but on iOS it the listener never fires…

1 Like

sdk version, @fedealconada ?

@notbrent
React Native: https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz
React: ^16.0.0
Expo: ^26.0.0

I also have problem with AddEventListener, callback is not fired on IOS, but on Android it works as expected

Does somebody have a solution ?

1 Like

@notbrent Has the iOS issue been resolved?

Same issue here,

SDK 31 with react navigation v3. When the app is closed and open a link via mobile safari the app opens and navigates to the correct page. But once app is in background and I try to change the URL, nothing is happening. I have linked the RTCLink library via Pods and added the necessary code to AppDelegate.m but I am completely out of ideas and tried everything I could find.

Still experiencing this issue in expo SDK 34 with Android. I can only detect the opening of a deep link when app is closed. When using addEventListener when the app is in background, as the documentation says, nothing happens.

I’m having the same issue, ExpoKit 35.

I expect it has something to do with the continueUserActivity handler. I can call it from one of multiple places, i.e.

[super application:application continueUserActivity:userActivity restorationHandler:restorationHandler]

or

[RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];

or

[[ExpoKit sharedInstance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];

But it doesn’t seem to make a difference.

Tracing it through the code, the function gets called with the correct url, but it seems to just never reach the event listener…
I’ve tried linking and unlinking RCTLinkingIOS via the Podfile, but no luck so far…

3 Likes

Have the same problem here. My sdk version is 40.0.0

I found the solution.
change this: Linking.addEventListener(‘url’, this.handleEvent)
to: Linking.addEventListener(‘url’, (data) => this.handleEvent(data))
It works for me.

@ chiu1028 Unfortunately this didn’t resolve the issue for me.

It’s Nov 2021, EXPO SDK 43 and the issue is still not resolved. The eventHandler works fine on android, but with iOS it doesn’t detect the re-entry back into the app.

Or perhaps there’s alternative auth flows I don’t know about? I’m trying to open a browser in order to get third-party permission and then redirect back into the expo app, where the eventHandler takes care of the incoming data. Any help?

EDIT: @chiu1028 Never-mind, sorry your solution did work for normal Linking.

I was unable to read the response because, I was using the “AuthSession.useAuthRequest” hook, and trying to listen to the response with “Linking.addEventListener”. Instead, I needed to to listen for the response with “response”, which was one of the methods returned on the useAuthRequest hook.