Open chy89310 opened 5 years ago
WARNING: 如果不按照这个表格,我们将无法帮助你,并将忽略你的问题。
cordova -v
cordova platform ls
import {JPush} from "@jiguang-ionic/jpush"; import {TextToSpeech} from "@ionic-native/text-to-speech";
constructor( public jpush: JPush, private tts: TextToSpeech, ) {
document.addEventListener( "jpush.receiveNotification", (event: any) => { this.jpushNotification(event, true) }, false );
document.addEventListener( "jpush.backgroundNotification", (event: any) => { this.jpushNotification(event, false) }, false ); }
jpushNotification(event, showAlert){ var content; if (this.device.platform == "Android") { content = event.alert; } else { content = event.aps.alert; } if (showAlert) { alert("Receive notification: " + JSON.stringify(event)); } this.speak(event.extras.content); }
speak(content){ this.tts.speak({text:mytext,locale:"zh-HK",rate:1.4}) .then(() => console.log('Success')) .catch((reason: any) => console.log(reason)); }
2. 进入极光开发者后台创建推送,并点选了 content-available 选项 3. app 在前台或刚进入后台都能正常触发监听事件并播报声音 4. app 进入后台一段时间后,或被删后台,能接收推送但监听事件没被触发 ## 背景 你尝试做过些什么? ## Debug logs 包括 Android 或 iOS 的日志: * iOS: XCode logs * Android: $ adb logcat / Android Studio logcat
原生会发送 jpush.backgroundNotification 事件,至于页面能不能接收到,要检查是不是 web 页面被销毁了,监听事件不起作用了
意思是 DOM 被註銷了麼?cordova 有辦法在 web 頁面以外的上下文監聽事件嗎?
WARNING: 如果不按照这个表格,我们将无法帮助你,并将忽略你的问题。
你的运行环境
cordova -v
): 8.1.2 (cordova-lib@8.1.1)cordova platform ls
): ios 4.5.5期望效果
实际效果
重现步骤
constructor( public jpush: JPush, private tts: TextToSpeech, ) {
document.addEventListener( "jpush.receiveNotification", (event: any) => { this.jpushNotification(event, true) }, false );
document.addEventListener( "jpush.backgroundNotification", (event: any) => { this.jpushNotification(event, false) }, false ); }
jpushNotification(event, showAlert){ var content; if (this.device.platform == "Android") { content = event.alert; } else { content = event.aps.alert; } if (showAlert) { alert("Receive notification: " + JSON.stringify(event)); } this.speak(event.extras.content); }
speak(content){ this.tts.speak({text:mytext,locale:"zh-HK",rate:1.4}) .then(() => console.log('Success')) .catch((reason: any) => console.log(reason)); }