import { Injectable } from '@angular/core' ; import { Platform } from '@ionic/angular' ; import { DataService } from './data.service' ; import { Router } from '@angular/router' ; import { AliyunPush } from 'libs/@ionic-native/aliyun-push/ngx' ; @ Injectable ( { providedIn : 'root' } ) export class PusherService { id = 1 ; jpush ; constructor ( private platform , private dataService , private router , private aliPush ) { } init ( ) { if ( ! this . platform . is ( 'cordova' ) ) return ; this . aliPush . getRegisterId ( ) . then ( id => { console . log ( id ) ; this . aliPush . onMessage ( ) . subscribe ( mess => { console . log ( mess ) ; } ) ; this . dataService . userDataLoader . subscribe ( loaded => { if ( loaded ) { this . aliPush . bindAccount ( this . dataService . user . phone ) ; } } ) ; } ) . catch ( err => { console . log ( err ) ; } ) ; } public registrationId : string ; devicePlatform : string ; sequence : number = 0 ; aliasResultHandler ( result ) { let sequence = result . sequence ; let alias = result . alias ; } ; errorHandler ( error ) { let sequence = error . sequence ; let code = error . code ; } ; initPush ( ) { document . addEventListener ( "jpush.openNotification" , ( event ) => { var content ; if ( this . devicePlatform == "Android" ) { content = event . alert ; } else { if ( event . aps == undefined ) { content = event . content ; } else { content = event . aps . alert ; } } this . router . navigate ( [ '/message' ] ) ; } , false ) ; } processCmd ( event ) { } }