我使用 FirebaseX 在我的应用程序中接收通知。 我在后台正确收到通知。但是当应用程序在前台时,没有任何反应......
我已经搜索过这个问题,但对我没有任何帮助。 我尝试在数据内容中包含以下数据(当服务器调用 url 发送通知时) [notification_foreground] => 真 [点击] => 真
这是我的插件列表:
cordova-plugin-androidx-adapter 1.1.0 "cordova-plugin-androidx-adapter"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-badge 0.8.8 "Badge"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-fcm-with-dependecy-updated 3.0.0 "Cordova FCM Push Plugin"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-firebasex 5.0.0 "Google Firebase Plugin"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.1.1 "cordova-plugin-ionic-webview"
cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification"
cordova-plugin-speechrecognition 1.1.2 "Speech Recognition"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"
ionic 信息:
Ionic:
Ionic CLI : 5.2.8
Ionic Framework : @ionic/angular 4.9.0
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.1, (and 23 other plugins)
Utility:
cordova-res : 0.5.1
native-run : 0.2.7
System:
NodeJS : v10.16.0
npm : 6.10.1
OS : Windows 10
订阅消息的代码...
this.firebase.onMessageReceived().subscribe(notification => {
console.log('NOTIFICATION !!!!');
console.log(notification);
alert( JSON.stringify(notification) );
if (notification['tap']) {
this.navCtrl.navigateRoot('/test');
} else {
alert( JSON.stringify(notification) );
}
});
当应用程序在后台时,我会收到通知,当我点击它时,我会看到警告消息和控制台日志。
但是当应用程序在前台时,什么也没有显示。
感谢您的帮助。
最佳答案
cordova-plugin-firebasex 插件无法与 cordova-plugin-local-notification 插件一起使用 我已经在当前的 ionic ios 应用程序中遇到了这个问题,但是android,它运行良好
根据@dpa99c
问题是这个插件和 cordova-plugin-local-notifications 都实现了相同的 UNUserNotificationCenterDelegate willPresentNotification 委托(delegate),并且由于委托(delegate)与其父类具有 1:1 的关系,所以只有一个委托(delegate)被调用 - 在这种情况下,响应由 cordova-plugin-local-notifications 创建的通知的 cordova-plugin-firebasex 委托(delegate)。
请查看以下链接以获取详细说明
https://github.com/dpa99c/cordova-plugin-firebasex/issues/230
解决方案: 请使用this带有 cordova-plugin-firebasex 的本地通知插件它在 android 和 iOS 两个平台上都能完美运行
关于firebase - ( ionic 4)当应用程序处于前台时无法使用 firebaseX 接收通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57954905/