Cordova-broadcaster in vue js setup

Hello,

I am new to the ionic platform and currently trying my hand at ionic + vue js setup.
In my app I am using the GitHub - navarrojava/cordova-broadcaster: Cordova Plugin to allow message exchange between javascript and native (and viceversa) plugin and trying to read the incoming intent in my ionic setup.

but the issue is in my App.vue I am always getting the “broadcaster” as undefined. I have installed using the instructions and build also goes fine. Not sure what is the issue.

  1. Is defining my bradcaster in App.vue the correct way?
  2. What is causing it as undefined ?

I have the below written in my App.vue

import broadcaster from '@ionic-native/broadcaster'
.
.
export default {

  name: "App",
  components: {
    IonApp,
  },
  beforeCreate() {
    if (isPlatform('hybrid')) {
      const listener = function (e) {
        console.log("android.intent.category.BROWSABLE: " + e);
      };
      const isGlobal = true;
      broadcaster.addEventListener(
        "android.intent.category.BROWSABLE",
        isGlobal,
        listener
      );
    }
  },
};

I am not qualified to answer, but perhaps this can be of use anyway :slight_smile:

If you are using Vue 3 you may need to write your code in setup () instead of beforeCreate (), because the broadcaster may not be ready yet.

Tried the above in create() but still getting “Msg: TypeError: Cannot read property ‘addEventListener’ of undefined”.

@Joshi I don’t know about create () :thinking: Did you try it in setup ()?

@codeluggage0
Thanks for your inputs. I did try that as well. No luck!

Instead I got it working in a simple manner using the already available Capacitor plugin : -

import { Plugins} from '@capacitor/core';
const { App } = Plugins;
.
.
.
setup() {
    
    if (isPlatform('hybrid')) {
           App.addListener('appUrlOpen', (data) => {
           console.log(data);
    });
    }

  },
1 Like