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

getLatestReferringParams is not giving the latest params on iOS by tapping on a link

Open yash-visit opened this issue 2 years ago • 2 comments

In the debug mode I can test the deep links by long pressing on link in notes app, as described in the documentation. I cannot pass the params by tapping on a link even after generating the build I'm using "react-native-branch": "^5.0.0"

following is the code snippet

componentDidMount() {
    this.branchUnsubscribe = branch.subscribe(({ error, params }) => {
          if (error) {
            console.error(`Error from Branch: ${error}`);
            this.loadApp();
            return;
          }
          console.log('branch subscribed', { params });
          this.checkBranch();
          // installReferrer
          if (params.uml_umr) {
            this.props.setDeviceInfo({
              installReferrer: `uml_umr=${params.uml_umr}`,
            });
          }
          // params will never be null if error is null
          if (params.uml_umc) {
            // user coming from magic link
            const magicCode = `uml_umc=${params.uml_umc}`;
            this.loadAppForMagicUser(magicCode);
          }
          // else {
          //   // normal app open
          //   this.loadApp();
          // }
        });
  }
      
   checkBranch = () => {
    Promise.all([
      branch.getLatestReferringParams(),
      branch.getFirstReferringParams(),
    ])
      .then(([resLatestParams, resFirstParams]) => {
        console.log('checkBranch fn response', {
          resLatestParams,
          resFirstParams,
        });
        if (!(resLatestParams.uml_umc || resFirstParams.uml_umc)) {
          if (resLatestParams.labsOrderId) {
            const orderId = resLatestParams.labsOrderId;
            this.props.setBranchConfig('labsOrderId', orderId);
          } else {
          // portion below never gets triggered because deeplink_path is never returned by resLatestParams
            const deepLinkPath = resLatestParams.$deeplink_path;
            switch (deepLinkPath) {
              case 'labsHome': {
                this.props.setBranchConfig('labsHome');
                break;
              }
              case 'freshchat': {
                this.props.setBranchConfig('freshchat');
                break;
              }
              case 'sso': {
                if (this.props.authToken) {
                  this.logout(
                    resLatestParams.encrypted,
                    resLatestParams.clientId
                  );
                } else {
                  this.handleSSO(
                    resLatestParams.encrypted,
                    resLatestParams.clientId
                  );
                }
                break;
              }
              default:
                break;
            }
          }

          // load app normally now
          this.loadApp();
        } else {
          // found magic code to open the app
          const magicCode = `uml_umc=${
            resLatestParams.uml_umc || resFirstParams.uml_umc
          }`;
          this.loadAppForMagicUser(magicCode);
        }
      })
      .catch((err) => {
        console.log({ err }, 'err in checkBranch method');
        this.loadApp();
      });
  };

Following are the snippets from AppDelegate.swift inside didFinishLaunchingWithOptions

#if DEBUG
    RNBranch.useTestInstance()
#endif
RNBranch.initSession(launchOptions: launchOptions, isReferrable: true)

outside of it

 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
   return RNBranch.application(app, open:url, options:options)
 }
 private func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
   return RNBranch.continue(userActivity)
 }

I've been struggling with it from past week and unable to find the solution for the same

yash-visit avatar Oct 05 '21 05:10 yash-visit

@yash-visit Could you enable logging through RNBranch.enableLogging() before the RNBranch.initSession() and provide the Branch SDK Logs for this user flow?

jf-branch avatar Oct 29 '21 07:10 jf-branch

Hi @jf-branch, I seem to have narrowed it down a little, the library is working fine if we create a new react native app with Objective-C code(AppDelegate.m) but not with swift. I basically set up a new react-native swift app and the latest version of the branch doesn't seem to be working with it. https://github.com/yash-visit/branchTest. Let me enable the logging I'll share it's response

yash-visit avatar Oct 29 '21 13:10 yash-visit