jpush / jpush-phonegap-plugin

JPush's officially supported PhoneGap/Cordova plugin (Android & iOS). 极光推送官方支持的 PhoneGap/Cordova 插件(Android & iOS)。
https://docs.jiguang.cn
MIT License
925 stars 350 forks source link

请将JPush的初始化方法,添加到[UIApplication application: didFinishLaunchingWithOptions:]方法中,否则JPush将不能准确的统计到通知的点击数量。 #389

Closed Story5 closed 5 years ago

Story5 commented 5 years ago

运行环境

期望效果

setApplicationIconBadgeNumber(0)可以清除ios角标

实际效果

未清除,一直有角标存在

重现步骤

背景

this.jPushPlugin.resetBadge();
this.jPushPlugin.setBadge(0);

以上代码放在了app.component.tsngOnInit

Debug logs

huangminlinux commented 5 years ago

setApplicationIconBadgeNumber 是设置手机端的badge值 setBadge 和 resetBadge 为设置服务端的 badge 值。

Story5 commented 5 years ago

以下方法,我都有设置

setApplicationIconBadgeNumber(0);
resetBadge();

但是在ios上,数字还是会在

huangminlinux commented 5 years ago

https://github.com/jpush/jpush-phonegap-plugin/blob/master/src/ios/Plugins/JPushPlugin.m#L355 可以检查这里是否有执行到。

Story5 commented 5 years ago

Xcode打过断点调试

1.第一次启动不会调用

  initJPush() {
    //极光推送开启
    this.sxjpush.init().then(success => {
      this.sxjpush.getRegistrationID();
      // 每次打开程序清除角标
      this.sxjpush. setApplicationIconBadgeNumber(0);
      this.sxjpush. resetBadge();
      // debug模式
      this.sxjpush.setDebugMode(false);
    });
  }

2.后面监听的代码会走

document.addEventListener("jpush.openNotification",
        (event: any) => {
          console.log(JPUSH_EVENT_openNotification," success:",JSON.stringify(event));
          this.getIOSApplicationIconBadgeNumber().then((badge:number)=>{
            let newBadge = badge - 1;
            this.sxjpush. setApplicationIconBadgeNumber(newBadge);
            this.sxjpush. setBadge(newBadge);
          });
          observer.next(event);
        },false);
huangminlinux commented 5 years ago

监听代码中的 setApplicationIconBadgeNumber 也不起作用?

Story5 commented 5 years ago

后面监听里的起作用,可以改变badge. 但是当我调用完init后,在promise里面调用setApplicationIconBadgeNumber不起作用

huangminlinux commented 5 years ago

ionic jpush 你用的什么插件?

Story5 commented 5 years ago

就是从这个仓库安装的呀,版本3.5.0

jpush-phonegap-plugin 3.5.0 "JPush" cordova-plugin-jcore 1.2.6 "JCore"

huangminlinux commented 5 years ago

init 方法没有返回 promise 你 .then 也没用啊

Story5 commented 5 years ago

有的呀...我看ts声明文件里有的

index.d.ts

声明文件我是通过md里面这行命令安装的

npm install --save @jiguang-ionic/jpush
huangminlinux commented 5 years ago

额,这里不应该返回 promise ,cordova 没有传入 success callback。是个定义错误。。

huangminlinux commented 5 years ago

init 方法是个同步接口,你可以直接将 then 内的操作放到 init 方法之后即可。 下个版本会修复这个问题。

Story5 commented 5 years ago

我试过在init后就调用,也不行

   //极光推送开启
   this.sxjpush.init();
   // 每次打开程序清除角标
   this.sxjpush.setApplicationIconBadgeNumber(0);
huangminlinux commented 5 years ago

jpush 相关 api 有在 platform.ready() 中调用吗?

Story5 commented 5 years ago

之前没有,试着移到platform.ready()中,可以了,多谢 顺便问一下,文档里我没有看到ios 10的清除监听,我应该怎么监听通知的清除事件,然后对我的badge减一