如何避免加载用于Web构建的Expo通知捆绑包? [英] How to avoid loading Expo notifications bundle for web build?
问题描述
我正在使用expo并响应本机网络.我已经将FCM集成到Web通知中,但是expo还加载了我不想要的通知包.
I am using expo and react native web. I have integrated FCM for notifications for web but expo also loads a notifications bundle which I do not want.
问题是当在浏览器中收到通知并单击消息时,应用程序获得了焦点,但崩溃并显示"TypeError:_emitter undefined".这是src/Notifications/Notifications.ts:40
The issue is when the notification is received in the browser and message is clicked, the app gets the focus but crashes saying "TypeError: _emitter is undefined". This is on this line in src/Notifications/Notifications.ts:40
_emitter.emit('notification', notification);
因此,似乎expo尝试使用其Notifications模块.我可以将其删除以进行网络构建吗?
So, it seems expo tries to use its Notifications module. Can I remove that for web build?
推荐答案
解决方案1-升级到expo@39.0.4:
npm install expo@39.0.4
解决方案2-初始化_emitter属性
- 安装以下软件包:
npm install --save fbemitter
- 在App.js/tsx文件中添加一个侦听器
import * as Notifications from 'expo/build/Notifications/Notifications'
// By calling "Notifications.default.addListener()" function,
// the _emitter variable will be initialized correctly
Notifications.default.addListener(event => {
console.log('message data', event.data)
})
这篇关于如何避免加载用于Web构建的Expo通知捆绑包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!