mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Platform } from '@ionic/angular';
|
|
import { CapacitorConfig } from '@capacitor/cli';
|
|
import { LocalNotifications, LocalNotificationSchema } from '@capacitor/local-notifications';
|
|
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class NativeNotificationService {
|
|
|
|
constructor(private platform: Platform,) {
|
|
this.askForPermission()
|
|
}
|
|
|
|
askForPermission() {
|
|
|
|
LocalNotifications.requestPermissions()
|
|
|
|
LocalNotifications.checkPermissions().then((data)=>{
|
|
//
|
|
}).catch((data)=>{
|
|
//
|
|
})
|
|
|
|
}
|
|
|
|
foregroundNotification() {
|
|
console.log('Local notification foreground')
|
|
LocalNotifications.addListener('localNotificationReceived', (notification) => {
|
|
console.log('Local Notification',notification)
|
|
})
|
|
}
|
|
|
|
sendNotificationChat({title = 'User', icon = '', message = 'hello'}) {
|
|
|
|
LocalNotifications.schedule({
|
|
notifications:[
|
|
{
|
|
title : title,
|
|
body : message,
|
|
id : new Date().getTime()
|
|
}
|
|
]
|
|
});
|
|
|
|
}
|
|
|
|
isDesktop() {
|
|
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
|
return true
|
|
} else {
|
|
return false
|
|
|
|
}
|
|
}
|
|
|
|
}
|