繁体   English   中英

Firebase 推送通知与 cordova 前景和背景 n

[英]Firebase push notifications with cordova foreground and background n

我正在使用 react Project 研究 Cordova。 我已经为 android 和 Z9E804D4E8DF198474 设置了 google firebase google-services.json 和 GoogleService-Info.plist 我正在使用以下 package 进行 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 反应的通知。

案例1:后台测试应用程序State

从 firebase 云消息发送通知并在后台测试应用程序 state / 最小化应用程序然后你会看到通知。

案例 2:在前台测试应用程序 State

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM