import { OneSignal } from '@ionic-native/onesignal/ngx';
providers: [
StatusBar,
SplashScreen,
OneSignal,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
import { OneSignal, OSNotification } from '@ionic-native/onesignal/ngx';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class PushService {
constructor(private oneSignal: OneSignal) { }
mensajes:any[] = [
{
title: 'Titulo de la push',
body: 'Este es el body de la push',
date: new Date()
}
];
configuracionInicial(){
this.oneSignal.startInit(ONESIGNAL_APP_ID, FIREBASE_SENDER_ID);
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification );
this.oneSignal.handleNotificationReceived().subscribe((noti) => {
// do something when notification is received
console.log('Notificación recibida', noti);
this.notificacionRecibida( noti );
});
this.oneSignal.handleNotificationOpened().subscribe((noti) => {
// do something when a notification is opened
console.log('Notificación abierta', noti)
});
this.oneSignal.endInit();
};
notificacionRecibida( noti: OSNotification ){
const payload = noti.payload;
const existePush = this.mensajes.find( mensaje=> mensaje.notificationID === payload.notificationID );
if( existePush ){
return;
}
this.mensajes.unshift( payload );
};
}
private pushService: PushService
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.pushService.configuracionInicial();
});
}
No hay comentarios.:
Publicar un comentario