带有科尔多瓦前景和背景的 Firebase 推送通知 n
Firebase push notifications with cordova foreground and background n
我正在使用 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);
});
}
});
通过使用上面的代码,我获得了令牌和负载。目前,我正在使用弹出窗口填充有效负载。有人可以帮我实现通知而不是弹出窗口吗?我在 google 中搜索了很多,但没有找到任何使用 Cordova React 实现通知的参考资料。
案例 1:在后台状态下测试应用程序
从 firebase 云消息发送通知并在后台状态下测试应用程序/最小化应用程序然后您将看到通知。
案例 2:在前台状态下测试应用程序
您应该使用一些类似于此插件的插件 https://github.com/katzer/cordova-plugin-local-notifications#readme 在应用程序处于前台时获取 firebase 通知。
我正在使用 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);
});
}
});
通过使用上面的代码,我获得了令牌和负载。目前,我正在使用弹出窗口填充有效负载。有人可以帮我实现通知而不是弹出窗口吗?我在 google 中搜索了很多,但没有找到任何使用 Cordova React 实现通知的参考资料。
案例 1:在后台状态下测试应用程序
从 firebase 云消息发送通知并在后台状态下测试应用程序/最小化应用程序然后您将看到通知。
案例 2:在前台状态下测试应用程序
您应该使用一些类似于此插件的插件 https://github.com/katzer/cordova-plugin-local-notifications#readme 在应用程序处于前台时获取 firebase 通知。