Ionic SignalR本地通知

时间:2019-02-05 05:32:03

标签: c# ionic-framework notifications signalr

来自SignalR的消息即将到来。我想在收到消息后向用户发送通知,但是功能消息未定义,这是什么原因。

console.log(“ abc”,mes)->消息显示在控制台中。 console.log(“ cba”,mes)->消息未显示在console.result-> cba未定义

home-page.ts

import { Component,EventEmitter } from '@angular/core';
import { hubConnection } from 'signalr-no-jquery';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import { AlertController,NavController } from '@ionic/angular';


@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})



export class HomePage {  
constructor(private localNotifications: LocalNotifications,public alertCtrl: 
 AlertController,public navCtrl: NavController) {       
  }

ngOnInit() {
let mes :string;
const connection = hubConnection('http://domain.tk/');
const hubProxy = connection.createHubProxy('signalrserver');
connection.start()
.done(function(){ 
 console.log('Now connected, connection ID=' + connection.id);  
 hubProxy.invoke('sendMessages');
})

.fail(function(){ console.log('Could not connect'); });

  hubProxy.on('sendMessages', function(message) {             
   mes = message;
   console.log("abc", mes); 
  });

 console.log("cba", mes);
 this.localNotifications.schedule({
  id: 1,
  text: mes    
  });

 }

}

0 个答案:

没有答案