Files
TaskHybrid/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs
2025-09-11 16:06:19 +02:00

37 lines
1.1 KiB
C#

using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
using Shiny;
using Shiny.Notifications;
using Shiny.Push;
namespace salesbook.Maui.Core.System.Notification;
public class FirebaseNotificationService(
IPushManager pushManager,
IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient,
INotificationManager notificationManager
) : IFirebaseNotificationService
{
public async Task InitFirebase()
{
CreateNotificationChannel();
var (accessState, token) = await pushManager.RequestAccess();
if (accessState == AccessState.Denied || token is null) return;
await integryRegisterNotificationRestClient.Register(token);
}
private void CreateNotificationChannel()
{
var channel = new Channel
{
Identifier = "salesbook_push",
Description = "Notifiche push di SalesBook",
Importance = ChannelImportance.High,
Actions = []
};
notificationManager.AddChannel(channel);
}
}