2022-01-26 17:28:55 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { Platform } from '@ionic/angular';
|
|
|
|
|
import { CapacitorConfig } from '@capacitor/cli';
|
2023-02-09 11:25:57 +01:00
|
|
|
import { LocalNotifications, LocalNotificationSchema } from '@capacitor/local-notifications';
|
2022-01-26 17:28:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class NativeNotificationService {
|
|
|
|
|
|
|
|
|
|
constructor(private platform: Platform,) {
|
|
|
|
|
this.askForPermission()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
askForPermission() {
|
|
|
|
|
|
|
|
|
|
LocalNotifications.requestPermissions()
|
|
|
|
|
|
2022-01-28 17:33:26 +01:00
|
|
|
LocalNotifications.checkPermissions().then((data)=>{
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2022-01-28 17:33:26 +01:00
|
|
|
}).catch((data)=>{
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2022-01-28 17:33:26 +01:00
|
|
|
})
|
|
|
|
|
|
2022-01-26 17:28:55 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 11:25:57 +01:00
|
|
|
foregroundNotification() {
|
2023-05-26 14:23:37 +01:00
|
|
|
|
2023-02-09 11:25:57 +01:00
|
|
|
LocalNotifications.addListener('localNotificationReceived', (notification) => {
|
2023-05-26 14:23:37 +01:00
|
|
|
|
2023-02-09 11:25:57 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 17:28:55 +01:00
|
|
|
sendNotificationChat({title = 'User', icon = '', message = 'hello'}) {
|
|
|
|
|
|
|
|
|
|
LocalNotifications.schedule({
|
|
|
|
|
notifications:[
|
|
|
|
|
{
|
2022-01-28 17:33:26 +01:00
|
|
|
title : title,
|
|
|
|
|
body : message,
|
|
|
|
|
id : new Date().getTime()
|
2022-01-26 17:28:55 +01:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isDesktop() {
|
|
|
|
|
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
|
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|