react-nativeexpobranch.io

Branch.subscribe from expo-branch doesn't receive the data if the app is already open


I managed to set up Branch.io successfully and managed to receive the deep linking data when I subscribe on component did mount. For the sake of debugging with release bundle (available only for android, generated with: expo build:android -t apk --release-channel test) I store the received data and pass it inside of a Text View.

Branch.subscribe(bundle => {this.props.AuthStore.testData = JSON.stringify(bundle);});

There are 2 scenarios, one working and one not working:

(Working) u don’t open the app → u navigate to some note (or gmail) → click the link → app is opened and the data from the link is being extracted on Branch.subscribe

(NOT working) u open the app → u minimize the app → u navigate to some note (or gmail) → click the link → app opens but the link data is not received and branch.subscribe is not triggered

Is there some configuration that I am missing? I tried subscribing on AppStateChange (foreground|background) + I tried using await Branch.getLatestReferringParams() (without any success in both scenarios)

Please help and thank you for reading, hope this helps other people as well.


Solution

  • The solution: use Linking from react-native.

    Branch fetches the first call when the app is opened. If the app is running in the background the links are being interrupted by different communication layer and Branch.io cannot be reached. Thats how I understood it, it doesn't mean I am 100% right, this is based on lots of console.logs, builds and debugging.

    Therefore you only need to call the branch link handling code. However on the backend, the Branch generated links need to contain the parameters in the URL in order for this to be feasible solution, because you won't get the object bundle from branch when handling links with the Linking module.