【发布时间】:2022-01-07 09:45:13
【问题描述】:
我做了以下改动:
如何发送通知,使用 firebase-admin 并获得成功结果:
admin.messaging().sendToDevice(
"token as string",
{
notification: {
title: 'title here',
body: 'body here'
}
},
{
priority: "high",
contentAvailable: true,
timeToLive: 2419200
});
React-native 代码,这是当应用程序在前台时:
useEffect(() => {
checkToken().then((token) => {
console.log(token);
// write to db
});
const unsubscribe = messaging().onMessage(async (remoteMessage) => {
console.log(remoteMessage);
});
return unsubscribe;
}, []);
我在 ios 文件夹中有 GoogleService-Info.plist 文件,我已经在 firebase 控制台 + teamid + appid 中上传了 APN。
随着 AppDelegate.m 的变化:
#import <Firebase.h>
....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
当应用程序在前台运行时我没有收到任何通知,我发送的方式一定有问题(可能我有错误的选项)或者,我在 react-native 中的配置错误,不是当然。我现在只为IOS做这个。
任何信息或解决方案都会有所帮助。
【问题讨论】:
-
你能检查一下PushNotification.onNotification=(message)=> {},从'react-native-push-notification'导入PushNotification;
-
后台消息是否有效?确保您遵循此rnfirebase.io 和此rnfirebase.io/messaging/usage 和此rnfirebase.io/messaging/usage/ios-setup 的每一步。还要确保在真实设备上测试消息,因为 fcm 永远不会在 Ios 模拟器上工作,如文档中所述。当我第一次这样做时,我发现这也很难集成。
-
谢谢您,我已按照上面的文档进行操作,直到现在才能正常工作。我会继续努力的。
标签: firebase react-native push-notification firebase-cloud-messaging react-native-fcm