离子通知 - Web服务上诉



我正在从事离子应用程序,我正在使用与服务器发送事件相关的本地通知(Spring Boot(不,我正在尝试打电话给网络服务evrey时间,我点击通知,但我没有得到我的" WebService" => localhost:8888/listTick

import { Component, OnInit } from '@angular/core';
import {Observable} from "rxjs";
import { Platform, AlertController } from '@ionic/angular';
import { LocalNotifications, ELocalNotificationTriggerUnit, ILocalNotificationActionType, ILocalNotification } from '@ionic-native/local-notifications/ngx';
import { Alert } from 'selenium-webdriver';
import { HttpClient } from '@angular/common/http';
@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
  scheduled = [];
  myData:any;
  constructor(public http: HttpClient,private plt: Platform, private localNotifications: LocalNotifications, private alertCtrl: AlertController) {
    this.connect();
    this.plt.ready().then(() => {
      this.localNotifications.on('click').subscribe(
        res => {
        let msg = res.data ? res.data.mydata : '';
        this.showAlert(res.title, res.text, msg);
      });
      this.localNotifications.on('trigger').subscribe(res => {
        let msg = res.data ? res.data.mydata : '';
        this.showAlert(res.title, res.text, msg);
      });
    });
  }
  getListTickets(){
    console.log('You will see this message every second');
    var url='http://localhost:8888/listtick';
    console.log("Clickeed");
    var result = this.http.get(url);
    return result;
  }
  connect(): void { //Get Notif From serverSentEvents
    let source = new EventSource('http://localhost:8080/get_mydata');
    source.addEventListener('message', message => {
        this.myData = JSON.parse(message.data);
        //alert(this.myData.data);
        this.localNotifications.schedule({
          id: 1,
          title: 'Attention',
          text: 'Test Notification',
          data: { mydata: this.myData.data },
          foreground: true // Show the notification while app is open
        });
      });
 }
    showAlert(header, sub, msg) {
      this.alertCtrl.create({
        header: header,
        subHeader: sub,
        message: msg,
        buttons: ['Ok']
      }).then(alert => alert.present());
    }
}

代码显示我尝试的内容,任何人都可以帮助我!

全部

我认为您已声明了,但您从未称呼该函数getListTickets()。也许您应该在点击订阅或任何想要的地方称其为单击订阅中。

this.localNotifications.on('click').subscribe(
   res => {
   this.getListTickets();
});

相关内容

最新更新