Search code examples
iosdeep-linkingurl-schemebranch.ioios-universal-links

How To Open Another of Our iOS Apps With Branch.io DeepLink From an iOS App


We have two iOS apps under our control. Let’s call them apps ABC and XYZ. Using the Branch.io SDK, we want to know how to:

  • Programmatically (Swift) create a deferred deep link inside of app ABC with the goal of taking the user to app XYZ. We would be using an existing URL Scheme for app XYZ since the backend server is not involved at all right now with this effort.
  • We want the Branch.io deep link to activate when a UIButton has been tapped (so no WebView involved here. Just a native button)
  • We want to pass along a 20ish long ID (letters and digits) and perhaps login information (if we can do it safely and securely) to the receiving app aka XYZ app.

We’ve followed the steps at https://docs.branch.io/pages/apps/ios/ to ensure the basics work. This includes the “Test deep link” section. That worked fine.

I believe I have read every single API document related to iOS and the Dashboard that Branch.io provides.

The most interesting ones to me for this quest were:

Code is here (with content changed so as to not identify which apps in the real world we're talking about since that's not important):

    private class func createBranchIoLink(someIdentifier: String) {

        // Create content reference
        let buo = BranchUniversalObject(canonicalIdentifier: "content/\(someIdentifier)")
        buo.canonicalUrl = "xyz://content/\(someIdentifier)" // example is https://example.com/content/123
        buo.title = "Some Title"
        buo.contentDescription = "Add it to the other app"

        // Create link reference
        let lp: BranchLinkProperties = BranchLinkProperties()
        lp.channel = "ios"
        lp.feature = "some-feature"

        buo.getShortUrl(with: lp) { (url, error) in
            print(url ?? "")
            print(error ?? "")
            print("ok done")
            // when I take the url given to us here, the URL takes me back to THIS app instead of the app I want!
        }
    }

Any help you can offer is appreciated. Thanks!


Solution

  • Brian from Branch here!

    You can generate links within app ABC to open app XYZ, but this also means that you will not be able to generate links that open app ABC. To achieve this flow, you would need to integrate the Branch SDK into both iOS apps, but create one app for XYZ on your Branch dashboard.

    Here are some things to keep in mind:

    This basically creates links that are specific to app XYZ and should open that app if the URI Scheme and Universal Links are set up properly and consistent with the Branch dashboard for app XYZ. App ABC only needs the Branch key to generate the links, and the Entitlements file or Info.plist does not need to be modified for app ABC.

    I hope this helps!