【发布时间】:2019-10-24 04:00:46
【问题描述】:
我尝试让react-native-firebase v6 在我的应用程序中工作。我使用 React Native 0.59.10。
我已经按照documentation安装了react-native-firebase v6。与 v5 不同,它没有指定将服务 MyFirebaseMessagingService 添加到 AndroidManifest.xml 中,所以我没有这样做。之后,应用在前台没有收到任何通知,但在后台收到了通知。
我尝试将MyFirebaseMessagingService 添加到AndroidManifest.xml 中,如下所示:
<service
android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
有一些进展。在我从 Firebase 控制台发送通知后,该应用程序立即崩溃。因此,我知道该应用知道收到的通知,但不知何故崩溃了。
下面是我导入和初始化监听器的代码。
import messaging from '@react-native-firebase/messaging';
import { Alert } from 'react-native';
// Initialize notifications
const init = () => {
try {
messaging().onMessage((message) => {
Alert.alert('Received', JSON.stringify(message));
});
} catch (err) {
Alert.alert('Error', err.message);
}
};
总之,我希望在应用程序处于前台时收到通知,但如果我不将MyFirebaseMessagingService 添加到AndroidManifest.xml,则不会发生任何事情。如果我添加它,应用程序将在收到通知时崩溃。
【问题讨论】:
-
发布堆栈跟踪。
-
@AbhayKoradiya 我已经找到了解决方案。谢谢。
-
@Dorklord 你能帮我在 v6 中显示本地通知吗?
标签: android firebase react-native react-native-firebase