带有cordova前景和背景n的Firebase推送通知

时间:2021-05-25 06:38:10

标签: android ios reactjs cordova firebase-cloud-messaging

我正在使用 React Project 开发 Cordova。我已经为 android 和 ios 设置了 google firebase google-services.json 和 GoogleService-Info.plist。我正在使用以下软件包进行 Firebase 通知设置。

https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated

FCM.requestPushPermission({
    ios9Support: {
        timeout: 10, // How long it will wait for a decision from the user before returning `false`
        interval: 0.3, // How long between each permission verification
    },
}).then((wasPermissionGiven) => {
    console.log(wasPermissionGiven);
    alert(JSON.stringify(wasPermissionGiven));
    if (wasPermissionGiven) {
        FCM.getAPNSToken().then((apnsToken) => {
            alert(JSON.stringify(apnsToken));
            console.log(apnsToken);
        });

        FCM.getToken().then((apnsToken) => {
            alert(JSON.stringify(apnsToken));
            console.log(apnsToken);
        });

        FCM.subscribeToTopic('handsome');
        const disposables = FCM.onNotification((payload) => {
            alert(JSON.stringify(payload.toString()));
            console.log('payload', payload);
        });
    }
});

通过使用上面的代码,我得到了令牌和有效载荷。目前,我正在使用弹出窗口填充有效负载。有人可以帮助我实现通知而不是弹出窗口吗?我在谷歌搜索了很多,没有找到任何使用 Cordova react 实现通知的参考。

1 个答案:

答案 0 :(得分:0)

案例 1:在后台状态下测试应用

从 firebase 云消息发送通知并在后台状态测试应用程序/最小化应用程序然后您将看到通知。

案例 2:在前台状态下测试应用

您应该使用一些类似于此插件 https://github.com/katzer/cordova-plugin-local-notifications#readme 的插件来在应用程序处于前台时获取 Firebase 通知。