You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yesterday, I successfully implemented the Plugin into my .NET MAUI app (uses XAML, MVVM, CommunityToolkit, .NET 8), and push notifications work. However, I have absolutely no clue if what I did is considered good or even acceptable.
Right now, I just inject NotificationsPermissions and FirebasePush services into my main ViewModel, and then I execute this function:
public async Task CheckPushNotificationPermissionsAsync()
{
var authStatus = await GetAuthorizationStatusAsync();
await RequestNotificationPermissionAsync();
// Ask for permission if not determined
if (authStatus == AuthorizationStatus.NotDetermined)
{
var isAccepted = await RequestNotificationPermissionAsync();
// Return if permission request is denied
if (!isAccepted) return;
}
// If permission is already denied, return
if (authStatus == AuthorizationStatus.Denied)
{
await UnregisterForPushNotificationsAsync();
UnsubscribeTopics();
UnsubscribeEvents();
return;
}
// Subscriptions
// TODO: Check multiple subscriptions
await RegisterForPushNotificationsAsync();
var token = GetFirebasePushNotificationToken();
// var notificationToken = await GetPushNotificationTokenAsync();
// if (!string.IsNullOrWhiteSpace(notificationToken)) await StorePushNotificationToken();
// SubscribeToTopicsAsync();
SubscribeToEvents();
}
The notifications work. However, I’ve seen different approaches, like using:
CrossNotificationPermissions.Current.RequestPermissionAsync().GetAwaiter().GetResult();
and initializing inside of App.xaml.cs, so I’m not sure what’s really the way to go.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey there,
Yesterday, I successfully implemented the Plugin into my .NET MAUI app (uses XAML, MVVM, CommunityToolkit, .NET 8), and push notifications work. However, I have absolutely no clue if what I did is considered good or even acceptable.
Right now, I just inject
NotificationsPermissions
andFirebasePush
services into my main ViewModel, and then I execute this function:The notifications work. However, I’ve seen different approaches, like using:
CrossNotificationPermissions.Current.RequestPermissionAsync().GetAwaiter().GetResult();
and initializing inside of App.xaml.cs, so I’m not sure what’s really the way to go.
Thanks a lot,
Sadri
Beta Was this translation helpful? Give feedback.
All reactions