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
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(实例成员)
此函数侦听从本机代码发送的事件
参数 | 类型 | 详情 |
---|---|---|
eventName | string |
****Returns:** Observable<any>
在收到事件时返回Observable
fireNativeEvent(eventName, eventData)
该函数将数据发送到本地代码
参数 | 类型 | 详情 |
---|---|---|
eventName | string | |
eventData | any |
****Returns:** Promise<any>
在事件成功触发时返回可解析的promise