Files
doneit-web/src/app/services/fcm.service.ts
T

65 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-10-30 15:22:35 +01:00
import { Injectable } from '@angular/core';
/* import {
2020-10-30 15:22:35 +01:00
Plugins,
PushNotification,
PushNotificationToken,
PushNotificationActionPerformed,
Capacitor
} from '@capacitor/core'; */
2020-10-30 15:22:35 +01:00
import { Router } from '@angular/router';
/* const { PushNotifications } = Plugins; */
2020-10-30 15:22:35 +01:00
@Injectable({
providedIn: 'root'
})
export class FcmService {
constructor(private router: Router) { }
/* initPush() {
2020-10-30 15:22:35 +01:00
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) => {
2022-04-28 09:32:27 +01:00
2020-10-30 15:22:35 +01:00
}
);
PushNotifications.addListener('registrationError', (error: any) => {
2022-04-28 09:32:27 +01:00
2020-10-30 15:22:35 +01:00
});
PushNotifications.addListener(
'pushNotificationReceived',
async (notification: PushNotification) => {
2022-04-28 09:32:27 +01:00
2020-10-30 15:22:35 +01:00
}
);
PushNotifications.addListener(
'pushNotificationActionPerformed',
async (notification: PushNotificationActionPerformed) => {
const data = notification.notification.data;
2022-04-28 09:32:27 +01:00
2020-10-30 15:22:35 +01:00
if (data.detailsId) {
this.router.navigateByUrl(`/home/notifications/notification-detail${data.detaisId}`);
}
}
);
} */
2020-10-30 15:22:35 +01:00
}