Detached app and Branch.io

If I want to use Branch.io for a detached ExpoKit app. How do I install it? I understand its inside the DangerZone but it says:

Note: This API only works with standalone builds created with exp build.

as noted here: https://docs.expo.io/versions/latest/sdk/branch

So I imagine I can’t use it. But can I instead install it manually following the branch.io documentation: React Native ?

yeah if you are doing a detached app, you can just install branch for react native the way you would with another detached project.

But this doesn’t work for me when I follow: React Native

I have to add:

pod 'react-native-branch', path: '../node_modules/react-native-branch'
pod 'Branch-SDK', path: '../node_modules/react-native-branch/ios'

And then my compiler complains because I have two versions of Branch. One provided by ExpoKit and another provided by Branch-SDK. But I need to be using the Branch-SDK one. Any ideas how I can force a specific pod to be used?

@darkwata Why can’t you leave just Branch inside Expo SDK?

pod 'react-native-branch', path: '../node_modules/react-native-branch'
#pod 'Branch-SDK', path: '../node_modules/react-native-branch/ios'

I can’t do that because when I run pod install without Branch-SDK it gives me:

$ pod install
[!] Unable to find a specification for `Branch-SDK` depended upon by `react-native-branch`

I don’t know the solution, but. U can try a thing.

Open node_modules/react-native-branch/react-native-branch.podspect and remove

s.dependency 'Branch-SDK'

Thanks I talked to @notbrent about this and he said I can use the Expo DangerZone and it should work. I don’t have to install anything.

Given the docs say “Note: This API only works with standalone builds created with exp build,” he said:

"i think that msg is just to say that it won’t work in expo client

but it should work in detached apps just fine also"

I will try this route as it does make sense.

1 Like

So I’ve been working on getting Branch to work by following the Branch guide: React Native

I have got it so that if you go to a branch link it will open my app. But I need Branch to pass some parameters to my app. This is where things fail.

The problem I face is that my subscriber never gets called on iOS and Android. Its unclear to me if I should be following all of the Branch steps because I think Expo should take care of some of the setup via the BranchManager.java and I don’t have to initialize branch. Or do I? I’m referring to these steps: React Native

I’m trying avoid having two versions of Branch in my app. This should be working with ExpoKit.

import { DangerZone } from "expo";

const branch = DangerZone.Branch;

const run = async () => {
  branch.subscribe(({ error, params }) => {
    console.info("branch test");
    console.info({ error });
    console.info({ params });
    if (error) {
      console.error("Error from Branch: " + error);
      return;
    }

    // params will never be null if error is null

    if (params["+non_branch_link"]) {
      const nonBranchUrl = params["+non_branch_link"];
      // Route non-Branch URL if appropriate.
      return;
    }

    if (!params["+clicked_branch_link"]) {
      // Indicates initialization success and some other conditions.
      // No link was opened.
      return;
    }

    // A Branch link was opened.
    // Route link based on data in params.
  });

  console.info("params");
  const lastParams = await branch.getLatestReferringParams(); // params from last open
  console.info({ lastParams });
  const installParams = await branch.getFirstReferringParams(); // params from original install
  console.info({ installParams });
};

run();

is branch apikey defined in application?

I was able to get this working by importing from DangerZone and copying in the example subscribe code, after I performed the AndroidManifest / Info.plist / entitlements steps linked in the react-native-branch documentation. Didn’t need to do modify any actual native code.

2 Likes

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