(广播)Broadcaster

Broadcaster

此插件添加了原生代码和应用程序之间的交换事件。
Repo(备用): https://github.com/bsorrentino/cordova-broadcaster

Installation(安装)

1.安装Cordova和Ionic原生插件:

$ ionic cordova plugin add cordova-plugin-broadcaster
$ npm install --save @ionic-native/broadcaster

2.添加插件到app's module

Supported platforms(支持平台)

Android
iOS

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)

此函数侦听从本机代码发送的事件

参数 类型 详情
eventName string

****Returns:** Observable
在收到事件时返回Observable

fireNativeEvent(eventName, eventData)

该函数将数据发送到本地代码

参数 类型 详情
eventName string
eventData any

****Returns:** Promise
在事件成功触发时返回可解析的promise

你可能感兴趣的:((广播)Broadcaster)