Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

capacitor-branch-deep-links

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capacitor-branch-deep-links

Capacitor plugin for Branch.io deep links

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.6K
increased by13.21%
Maintainers
1
Weekly downloads
 
Created
Source

Capacitor plugin for branch.io deep links.

npm install capacitor-branch-deep-links

Usage

import { Plugins } from '@capacitor/core';
import { Platform } from '@ionic/angular';
import { BranchInitEvent } from 'capacitor-branch-deep-links';

const { BranchDeepLinks, SplashScreen } = Plugins;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {
  constructor(private platform: Platform) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      BranchDeepLinks.addListener('init', (event: BranchInitEvent) => {
        // Retrieve deeplink keys from 'referringParams' and evaluate the values to determine where to route the user
        // Check '+clicked_branch_link' before deciding whether to use your Branch routing logic
        console.log(event.referringParams);
      });

      BranchDeepLinks.addListener('initError', (error: any) => {
        console.error(error);
      });

      SplashScreen.hide();
    });
  }
}

Android setup

Follow the Branch docs to:

  1. Configure Branch

Update src/main/res/values/strings.xml with your configuration:

  <?xml version='1.0' encoding='utf-8'?>
  <resources>
      <string name="app_name">Ionic Starter</string>
      <string name="title_activity_main">Ionic Starter</string>
      <string name="package_name">io.ionic.starter</string>
      <string name="fileprovider_authority">io.ionic.starter.fileprovider</string>
+     <string name="custom_url_scheme">io.ionic.starter</string>
+     <string name="branch_key">key_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>
+     <string name="branch_test_key">key_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>
  </resources>

Register the plugin in your Activity:

+ import co.boundstate.BranchDeepLinks;

  public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      // Initializes the Bridge
      this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
        // Additional plugins you've installed go here
        // Ex: add(TotallyAwesomePlugin.class);
+       add(BranchDeepLinks.class);
      }});
    }
  }

Declare BranchApp as your application class in src/main/AndroidManifest.xml:

  <application
+     android:name="io.branch.referral.BranchApp"

Provide your Branch config within <application>:

<meta-data android:name="io.branch.sdk.BranchKey" android:value="@string/branch_key" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="@string/branch_test_key" />
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" /> <!-- Set to true to use test key -->

Add your Branch App Links (optional) in a new <intent-filter> within <application>:

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https" android:host="xxxx.app.link" />
    <data android:scheme="https" android:host="xxxx-alternate.app.link" />
</intent-filter>

Test that it works!

iOS setup

Follow the Branch docs to:

  1. Configure Branch
  2. Configure bundle identifier
  3. Configure associated domains
  4. Configure entitlements
  5. Configure Info.plist

You can use the Branch wizard to walk you through the process
(skip the Get the SDK files and Start a Branch session steps)

Add Branch to your Podfile:

  target 'App' do
    capacitor_pods
    # Add your Pods here
+   pod 'Branch';
  end

Update the project:

npx cap update ios

Make the following changes to your AppDelegate.swift file:

+ import Branch

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
+   Branch.setUseTestBranchKey(true) // if you are using the TEST key
+   Branch.getInstance()!.initSession(launchOptions: launchOptions)
    return true
  }

  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    // Called when the app was launched with a url. Feel free to add additional processing here,
    // but if you want the App API to support tracking app url opens, make sure to keep this call
+   Branch.getInstance()!.application(app, open: url, options: options)
    return CAPBridge.handleOpenUrl(url, options)
  }

  func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    // Called when the app was launched with an activity, including Universal Links.
    // Feel free to add additional processing here, but if you want the App API to support
    // tracking app url opens, make sure to keep this call
+   Branch.getInstance()!.continue(userActivity)
    return CAPBridge.handleContinueActivity(userActivity, restorationHandler)
  }

Test that it works!

Keywords

FAQs

Package last updated on 10 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc