import {
AppRegistry,
StyleSheet,
Text,
View,
Platform,
NativeAppEventEmitter,
DeviceEventEmitter,
} from 'react-native'; //添加DeviceEventEmitter componentDidMount() {
if(Platform.OS=='android'){
this.subscription = DeviceEventEmitter.addListener('userNameDidChange',(userName) => {
alert('通知');
})
}else {
this.subscription = NativeAppEventEmitter.addListener('userNameDidChange',(userName) => {
alert('通知');
})
} }, 移除DeviceEventEmitter
componentWillUnmount() {
// 移除
this.subscription.remove();
}, 发送通知
DeviceEventEmitter.emit('userNameDidChange', '通知来了'); OK, 完成!

最新文章

  1. PostgreSQL-PL/pgSQL-cursor,loop
  2. SQL SQL语句的增删改查
  3. 在VFP6中模拟CursorAdapter的功能
  4. 将 List<UserInfo>中的对象按照UserInfo.name进行分组
  5. underscore源码阅读记录
  6. php动态获取函数参数
  7. BZOJ3613 南园满地堆轻絮-二分法
  8. Node.js实践第一天
  9. ACboy needs your help again!
  10. <script src="xxx.php"></script>
  11. H3C无线路由器安装与设置
  12. python 操作MongoDB
  13. 【Zabbix】Zabbix Server自动发现
  14. div的onclick事件怎么失效了?
  15. 7.4 electirc.c -- 计算电费
  16. Caused by: java.io.FileNotFoundException: velocity.log (No such file or directory)
  17. SDK安装详解以及adb的来源
  18. linux下搭建SVN
  19. CSS快速入门-属性和伪类
  20. 如何用有NFC功能的手机微信给公交卡充值?入口在那里?

热门文章

  1. Visio模具与模版
  2. python密码输入模块getpass
  3. mysql中的表操作
  4. 使用svndumpfilter exclude来清理svn库的废弃文件实现差别备份
  5. 洛谷$P$2468 粟粟的书架 $[SDOI2010]$ 主席树
  6. Spring MVC拦截器配置
  7. Linux学习之路--shell学习
  8. Python 植物大战僵尸代码实现: 图片加载和显示切换
  9. 23.python虚拟环境配置
  10. 10.Python中print函数中中逗号和加号的区别