Linking eventListener (url) not being triggered as expected from links back from the browser (iOS only)

Please provide the following:

  1. SDK Version: 43.0.1
  2. Platforms(Android/iOS/web/all): iOS
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

I’ve been struggling for days trying to figure out why the Linking eventListener doesn’t seem to work. Iam setting up the event listener correctly:
Linking.addEventListener(“url”, handleStravaRedirect);

where “handleStravaRedirect” is the callback function to be called after the user grants my app permission on the 3rd party website. The problem is, this function never gets called after the redirect back to my app. I thought I was doing something wrong, but when I tried the auth flow on android, the event handler triggered as expected.

Are there any extra steps I need to do to make Linking work on iOS?

Other information:
I’m importing Linking like so:

  • import * as Linking from “expo-linking”; (It would be nice if there was a default export for this; kind of confusing)

  • To make the Auth Request and open the web browser, I’m using: AuthSession.useAuthRequest

  • When I log “Linking.addEventListener” right above where it gets linked, the function is there and I receive no errors that adding the event listener failed, So I’m assuming that part is set up properly and the problem is purely on reopening of my app from the browser.

  • I’m having the same issue in Dev when I’m using the "exp:// " scheme and in Testflight when I use my custom “herofit://” scheme.

Please help, I’m stumped!

EDIT: One other thing I noticed:
It seems like iOS handles the app being pushed to the background & the redirect differently than android handles it, almost like the Linking eventListener doesn’t even know the user left the app in the first place.

Edit2: My issue seems to be the same as the one over here: Expo deeplinking issue with addEventListener - #14 by chiu1028

OK after 3 days of grinding my gears, I was able to figure out the problem:

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.

This is my fault, however as a newcomer coming into react native and expo development, it was unclear what and why I should be using “AuthSession.useAuthRequest” vs regular Linking. It would be helpful if this was elaborated on in the docs.

I hope this post will find someone else confused and save them a lot of time.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.