Can not install branch-cordova-sdk plugin

Hi

I did following:

  1. I installed the plugin with:
ionic cordova plugin add branch-cordova-sdk
  1. I added the settings to my config.xml (I replaced the values with my values from the dashboard.branch.io account)
  <plugin name="branch-cordova-sdk" spec="^2.5.0" />
  <branch-config>
    <branch-key value="....." />
    <uri-scheme value="branchcordova" />
    <link-domain value="cordova.app.link" />
    <ios-team-release value="......." />
  </branch-config>
  1. I added the initialization code from provided by branch.io to my app.component.ts
// sample app.component.js
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';

import { TabsPage } from '../pages/tabs/tabs

@Component({
  template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
  rootPage = TabsPage;

  constructor(platform: Platform) {
    platform.ready().then(() => {
      StatusBar.styleDefault();
      Splashscreen.hide();
      handleBranch();
    });

    platform.resume.subscribe(() => {
      handleBranch();
    });

    // Branch initialization
    const handleBranch = () => {
      // only on devices
      if (!platform.is('cordova')) { return }
      const Branch = window['Branch'];
      Branch.initSession(data => {
        if (data['+clicked_branch_link']) {
          // read deep link data on click
          alert('Deep Link Data: ' + JSON.stringify(data));
        }
      });
    }
  }
}

Everything builts and compile until here.
But when I deploy the app to my real ios-device the application crashes on start.

I saw a script error ‘plugin_not_installed’.

Do I something wrong?

Every tip is welcome.

Cheers,
Oliver

Hoi,

A couple of thoughts

  1. No devapp right?
  2. Is it possible that handleBranch is actually ran to early respectively before platform is ready

According your above code const handleBranch = () => { is in your constructor so even if you call it in platform.ready() it may be executed on init?

Also side note, not the problem I guess, but I don’t initialize it onResume

Could you try:

constructor(private platform: Platform) {
  platform.ready().then(() => {
    StatusBar.styleDefault();
    Splashscreen.hide();
    handleBranch();
  });
}

 // Branch initialization
private handleBranch() {
  // only on devices
  if (!this.platform.is('cordova')) { return }
  const Branch = window['Branch'];
  Branch.initSession(data => {
    if (data['+clicked_branch_link']) {
      // read deep link data on click
      alert('Deep Link Data: ' + JSON.stringify(data));
    }
  });
  1. If doesn’t work, have you already try to remove/add plugin again? Same with the platform?

P.S.: Side side note, isn’t the key/ios-team-release etc. you display above from your config.xml secret? Just in case you would like to replace them with fake value, like PW99999999 instead of PW4…

Hi @reedrichards

Thanks for your post.
You were on the right way I think with the DevApp.
The error happened actually only on the DevApp.
But the cause was another plugin -> OnSignal :-///

On my real device is no error :slight_smile:
And after I pushed a notification to my device, I clicked on the notification, it opens my app and recognized the deeplink :slightly_smiling_face:

And the config.xml settings were not mine. They were from the branch.io example.
But I changed it now :slight_smile:

Thanks for your help and effort.

I hope I can retaliate sometime

best regards
Oliver

1 Like

Nice to hear it worked out!

No worries, really interesting, I almost never create function as you display in your example, I’ve learnt something, thx :slight_smile:

Cya

I copied the code-example from branch.io just to see quickly, whether it works or not.
But after it looks to work, I guess I will refactore the code that it fits in my structure :slight_smile:

1 Like