jpush-phonegap-plugin icon indicating copy to clipboard operation
jpush-phonegap-plugin copied to clipboard

iOS 被删后台后不能触发 jpush.backgroundNotification 的监听事件

Open chy89310 opened this issue 6 years ago • 2 comments

WARNING: 如果不按照这个表格,我们将无法帮助你,并将忽略你的问题。

你的运行环境

  • 插件版本:
  • 平台(Android / iOS): iOS
  • Cordova version (cordova -v): 8.1.2 ([email protected])
  • Cordova platform version (cordova platform ls): ios 4.5.5
  • Ionic Version (if using Ionic): CLI 4.12.0

期望效果

  1. 手机按home进入后台,可以监听 jpush.backgroundNotification 事件并触发回掉.
  2. 手机双击home键把app在后台删掉(或iOS为了优化内存自动删掉后台)后,依然可以监听 jpush.backgroundNotification 事件并触发回掉.

实际效果

  1. 手机按home进入后台后,一段时间内还能监听 jpush.backgroundNotification 事件,但过了一段时间(约15分钟)后,即使app还在后台,已经不能监听 jpush.backgroundNotification 事件了
  2. 手机双击home键并删除app后台后,jpush.backgroundNotification 立即不能被触发。

重现步骤

  1. 在 home.ts(主页面)中监听 jpush 事件
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));
}

  1. 进入极光开发者后台创建推送,并点选了 content-available 选项
  2. app 在前台或刚进入后台都能正常触发监听事件并播报声音
  3. app 进入后台一段时间后,或被删后台,能接收推送但监听事件没被触发

背景

你尝试做过些什么?

Debug logs

包括 Android 或 iOS 的日志:

  • iOS: XCode logs
    • Android: $ adb logcat / Android Studio logcat

chy89310 avatar Apr 03 '19 08:04 chy89310

原生会发送 jpush.backgroundNotification 事件,至于页面能不能接收到,要检查是不是 web 页面被销毁了,监听事件不起作用了

JoshLipan avatar Apr 12 '19 03:04 JoshLipan

原生会发送 jpush.backgroundNotification 事件,至于页面能不能接收到,要检查是不是 web 页面被销毁了,监听事件不起作用了

意思是 DOM 被註銷了麼?cordova 有辦法在 web 頁面以外的上下文監聽事件嗎?

chy89310 avatar Apr 12 '19 03:04 chy89310