react-native-branch-deep-linking-attribution icon indicating copy to clipboard operation
react-native-branch-deep-linking-attribution copied to clipboard

Android / IOS issues on RN >= 0.61.5

Open jpgarcia opened this issue 4 years ago • 16 comments

We're integrating the library in a RN 0.61.5 project and we found several issues in the process.

In order to make sure that the issues are 100% related to the library we started a new RN project from scratch and performed all the steps described in the docs.

Here are details:

Dependencies

react-native: 0.61.5 react-native-branch: 5.0.0-beta-1 (also tried pointing the master branch to get the 5.0.0-beta-2)

Android Issues

  • When the app is in Foreground neither onOpenStart nor onOpenComplete events are triggered. The only way to get notified is by going to Background mode and return to Foreground

  • Related to the previous one. Going back and forth from Background to Foreground mode will trigger the event over and over again. Not sure is this is by design but you'll end up, for instance, redirecting to a screen multiple times.

Note: IOS works as expected and the events are cleared up

  • Refreshing the app with CMD+R (IOS) or R + R (Android) has the same behaviour as the Background/Foreground issue described above

Note: IOS works as expected and the events are cleared up

  • When using URL Schemas like "myapp://" the root uri field in the onOpenComplete event is null while with Universal Links (both branch and non-branch) works as expected

IOS Issues

  • Using Linking.getInitialURL returns null (ONLY in "Debug Mode")
  • When using URL Schemas like myapp:// the root uri field in the onOpenComplete event is null while with Universal Links (both branch and non-branch) works as expected

@jdee If you want I can publish a public repo with this example including all native configuration so you can check and play around. In any case below you'll find the JS code I used to replicate them

import React, {useState, useEffect} from 'react';
import branch from 'react-native-branch';
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  Text,
  StatusBar,
  Linking,
} from 'react-native';

const App = () => {
  const [url, setUrl] = useState({});
  const [branchUrl, setBranchUrl] = useState({});
  const [openStartUrl, setOpenStartUrl] = useState({});
  const [openCompleteUrl, setOpenCompleteUrl] = useState({});
  const [eventListenerUrl, setEventListenerUrl] = useState({});

  useEffect(() => {
    const processInitialUrl = async () => {
      const result = await Linking.getInitialURL();
      setUrl({result});

      const params = await branch.getLatestReferringParams(true);
      setBranchUrl({params});
    };

    processInitialUrl();
  }, []);

  useEffect(() => {
    const unsubscribe = branch.subscribe({
      // IMPORTANT: This flag will prevent events for being triggered when first state of the app is "closed"
      // as those are handled by the processInitialUrl method
      checkCachedEvents: false,
      onOpenStart: (payload) => {
        setOpenStartUrl({...payload, timestamp: Date.now()});
      },
      onOpenComplete: (payload) => {
        setOpenCompleteUrl({...payload, timestamp: Date.now()});
      },
    });

    return () => unsubscribe();
  }, []);

  useEffect(() => {
    const listenerId = Linking.addEventListener('url', (payload) => {
      setEventListenerUrl({...payload, timestamp: Date.now()});
    });

    return () => Linking.removeEventListener(listenerId);
  }, []);

  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <ScrollView contentInsetAdjustmentBehavior="automatic">
          <Text style={[styles.text, styles.title]}>Initial</Text>
          <Text style={styles.text}>
            getInitialURL: {JSON.stringify(url, null, 1)}
          </Text>
          <Text style={styles.text}>
            getLatestReferringParams: {JSON.stringify(branchUrl, null, 1)}
          </Text>

          <Text style={[styles.text, styles.title]}>Events</Text>

          <Text style={styles.text}>
            openStartUrl: {JSON.stringify(openStartUrl, null, 1)}
          </Text>
          <Text style={styles.text}>
            openCompleteUrl: {JSON.stringify(openCompleteUrl, null, 1)}
          </Text>
          <Text style={styles.text}>
            eventListenerUrl: {JSON.stringify(eventListenerUrl, null, 1)}
          </Text>
        </ScrollView>
      </SafeAreaView>
    </>
  );
};

const styles = StyleSheet.create({
  text: {
    marginTop: 5,
    paddingHorizontal: 10,
  },
  title: {
    fontWeight: 'bold',
  },
});

export default App;

jpgarcia avatar Jun 04 '20 22:06 jpgarcia

Hi guys do you have any update on this?

jpgarcia avatar Jun 10 '20 19:06 jpgarcia

Looks kind of abandoned now... What is the state of the v5 release?

lukebars avatar Jun 16 '20 08:06 lukebars

Yes, we're considering other alternatives :pensive:

jpgarcia avatar Jun 17 '20 21:06 jpgarcia

Sorry, I've had a lot on my plate recently. I'll have to digest this. In the future, if you have any issues with Branch, I'd strongly recommend contacting [email protected]. You'll always get a quick response there, and they won't let me forget.

jdee avatar Jun 17 '20 22:06 jdee

Hi, are there any updates on this? Trying to get branch to work in RN 0.61.5 too, but without success.. Thanks for some info!

skizzo avatar Jun 30 '20 23:06 skizzo

Sorry for the long delay. We'll be doing a release in the next week or so. Please bear with us and let support know if we're holding up anything critical so we can prioritize.

jdee avatar Jun 30 '20 23:06 jdee

Also please see #582. I think this conflicts with the original report on iOS, but we were not able to generate an onOpenStart callback or supply the uri parameter in the onOpenComplete callback (these come from the same place) on iOS when launched from a Universal Link. We were not looking in the right place. Custom URIs were working fine in my testing.

jdee avatar Jun 30 '20 23:06 jdee

In my testing on 61.5 and 5.0.0 beta 1, universal links (branch shortened to *.app.link) for iOS 13 open correctly for both cold start and background resume. Same with android. I do not use url schemes.

jamesholcomb avatar Jul 08 '20 21:07 jamesholcomb

@jdee Is there a release that resolves this issue? @jpgarcia were you able to get android onOpenStart functioning as expected? react-native: 0.62.2 react-native-branch: 5.0.0-beta-1

danstepanov avatar Jul 23 '20 04:07 danstepanov

Sorry for the continued delay. I plan to do a release today with some updates that should at least improve the situation on iOS. I may also have some improvement for you on Android if I can get to a testable spot there. I feel your pain with RN upgrades. I have a tough time keeping the little examples in the repo up to date and running to be able to test.

jdee avatar Jul 23 '20 15:07 jdee

Release 5.0.0-rc.1 has the fix for Universal Links on cold launch on iOS. There is a rebuild-testbed-simple branch in the repo with the same testbed_simple app, but the RN scaffolding was rebuilt with 0.62.2 from scratch via react-native init. This works fine for me in testing on an Android emulator, though some cases are best tested on a device. I wanted to get this release out for some of the other changes. I'd like to do the final 5.0.0 release in a week, with fixes for whatever remains here. I'm currently charging an Android device to do some in-depth testing. Meanwhile you're welcome to use the updated testbed_simple to verify any of your use cases. I'll be looking at that tomorrow.

jdee avatar Jul 24 '20 00:07 jdee

Could you comment on https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/issues/530#issuecomment-640347950

jamesholcomb avatar Jul 24 '20 18:07 jamesholcomb

@danstepanov I'm sorry to say that we decided to move to Firebase Dynamic Links 😢

jpgarcia avatar Jul 27 '20 18:07 jpgarcia

After implementing 5.0.0-rc-1, Android still does not register open or install events in the dashboard.

danstepanov avatar Jul 27 '20 18:07 danstepanov

Any updates on this?

StarryFire avatar Sep 22 '20 23:09 StarryFire

The first 3 issues mentioned for Android seems to have been fixed in the latest v5 version 🚀🚀

StarryFire avatar Sep 29 '20 16:09 StarryFire