关闭应用程序时,通过离子存储保存Onesignal通知

时间:2020-03-21 17:19:49

标签: android cordova ionic-framework push-notification onesignal

我正在尝试在我的离子应用程序中保存Onesignal通知,但仅在应用程序处于焦点或背景中时才保存。当应用关闭并收到通知时,它不会存储它。插件版本为2.5.0,平台为android。我正在使用以下代码:

setupPush() {
    // I recommend to put these into your environment.ts
    this.oneSignal.startInit('APP_ID', 'GOOGLE_PROJECT_NUMBER');

    this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.None);

    // Notifcation was received in general
    this.oneSignal.handleNotificationReceived().subscribe(data => {
      console.log(data.payload);
      this.storage.ready().then(()=>{
        this.storage.get("notifications").then((res)=>{
          if(res == undefined)
            res = [];
          res.push({title: data.payload.title, body: data.payload.body});
          this.storage.set("notifications", res).catch((e)=>{
            console.log(e);
          });
        }).catch(e=>{
          console.log(e);
        });
      });
    });

    // Notification was really clicked/opened
    this.oneSignal.handleNotificationOpened().subscribe(data => {
      // Just a note that the data is a different place here!
      console.log(data);
      this.router.navigate(['notif']);
    });
    this.oneSignal.endInit();
  }

0 个答案:

没有答案