我有FCM推送通知和本地通知代码一起工作。但是有时当我生成本地通知并且应用程序处于前台时,不会调用该通知的订阅者。
离子信息: 离子性:
ionic (Ionic CLI) : 4.10.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.1
科尔多瓦:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.0.1, (and 24 other plugins)
系统:
ios-sim : 7.0.0
NodeJS : v10.15.1 (/usr/local/bin/node)
npm : 6.9.0
OS : macOS Mojave
Xcode : Xcode 10.0 Build version 10A255
Cordova插件:
cordova-plugin-local-notification 0.9.0-beta.3 "LocalNotification"
cordova-plugin-fcm-with-dependency-updated-apns 1.0.0 "Cordova FCM Push Plugin"
cordova-plugin-ionic-webview 4.0.1 "cordova-plugin-ionic-webview"
离子代码:
this.fcm.onNotification().subscribe(data => {
let object = data
if (object.wasTapped) {
console.log("Received in background");
// console.log(JSON.stringify(object));
console.log('Do whatever you want');
}
else {
console.log("Received in foreground");
// console.log(JSON.stringify(object));
let notification: LocalNotificationState = {
id: (Math.floor(Math.random()*90000) + 10000),
text: object.body || object.aps.alert.body,
title: object.title || object.aps.alert.title,
vibrate: true,
lockscreen: true,
foreground: true,
progressBar: false
}
this.localNotificationProvider.schedule(notification)
if (object) {
this.localnotification.setDefaults(object)
}
this.localnotification.on('click').subscribe((obj) => {
console.log('Do whatever you want');
})
}
})
预期结果: 如果通知是在前台生成的,则应调用通知订阅者
实际结果: 有时本地通知订阅者没有被呼叫。