Broadcaster
This plugin adds exchanging events between native code and your app.
Repo: https://github.com/bsorrentino/cordova-broadcaster
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-broadcaster $ npm install --save @ionic-native/broadcaster@4
- Add this plugin to your app's module
Supported platforms
- Android
- iOS
- Browser
Usage
import { Broadcaster } from '@ionic-native/broadcaster';
constructor(private broadcaster: Broadcaster) { }
...
// Listen to events from Native
this.broadcaster.addEventListener('eventName').subscribe((event) => console.log(event));
// Send event to Native
this.broadcaster.fireNativeEvent('eventName', {}).then(() => console.log('success'));
Instance Members
addEventListener(eventName)
This function listen to an event sent from the native code
Param | Type | Details |
---|---|---|
eventName |
string
|
Returns: Observable<any>
Returns an observable to watch when an event is received
fireNativeEvent(eventName, eventData)
This function sends data to the native code
Param | Type | Details |
---|---|---|
eventName |
string
|
|
eventData |
any
|
Returns: Promise<any>
Returns a promise that resolves when an event is successfully fired