Files
doneit-web/src/app/services/fcm.service.ts
T
2022-04-28 09:32:27 +01:00

65 lines
1.5 KiB
TypeScript

import { Injectable } from '@angular/core';
/* import {
Plugins,
PushNotification,
PushNotificationToken,
PushNotificationActionPerformed,
Capacitor
} from '@capacitor/core'; */
import { Router } from '@angular/router';
/* const { PushNotifications } = Plugins; */
@Injectable({
providedIn: 'root'
})
export class FcmService {
constructor(private router: Router) { }
/* initPush() {
if (Capacitor.platform !== 'web') {
this.registerPush();
}
}
private registerPush() {
PushNotifications.requestPermission().then((permission) => {
if (permission.granted) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// No permission for push granted
}
});
PushNotifications.addListener(
'registration',
(token: PushNotificationToken) => {
}
);
PushNotifications.addListener('registrationError', (error: any) => {
});
PushNotifications.addListener(
'pushNotificationReceived',
async (notification: PushNotification) => {
}
);
PushNotifications.addListener(
'pushNotificationActionPerformed',
async (notification: PushNotificationActionPerformed) => {
const data = notification.notification.data;
if (data.detailsId) {
this.router.navigateByUrl(`/home/notifications/notification-detail${data.detaisId}`);
}
}
);
} */
}