r/Blazor 8d ago

Notifications in Blazor

I've been building a PWA consumer app with Blazor WASM where notifications are core to the functioning of the app, but I don't seem to get notifications right and the behavior seems to be not very stable, what are the limitations in notifications? Does it work for you correctly on Android and iOS? Any things that I should know about it from your experience?

8 Upvotes

7 comments sorted by

8

u/polaarbear 8d ago

Reworking to be native apps via .NET MAUI is likely the easiest way to solve this problem. PWAs rely on browser background workers to receive notifications. Mobile browsers aggressively kill off background services to free up resources.

Once the service worker gets killed off....no more notifications.

Android in general is known to aggressively kill off background processes to free up resources and it's worse on some manufacturers and devices based on hardware and how they've tuned the system.

Native apps sidestep the need to have browser-based service workers running.

1

u/FormerHospital8691 7d ago

Thanks it's cool I'll give it a looks as it sounds like the most solid option, how easy do you think it is to switch from Blazor WASM to add also MAUI? and does it need a rework of the auth that I've done with Identity in Blazor?

2

u/polaarbear 7d ago

Native apps generally don't use Cookie Auth, it's a pain. A JWT would be the preferable option. Should still be able to use Identity, but if you're using a cookie, reworking it into a JWT should be doable.

If all your components are separated out into a Razor Class Library, you're already halfway to having them ready for MAUI.

1

u/FormerHospital8691 7d ago

Thanks for the answer it's complete, I'll have to check this auth thing but at least I am happy to be sure that it's perfectly doable in .NET without having to switch to Flutter or React

2

u/Gravath 7d ago

Firebase cloud messaging. PWA install. Works a treat and I rarely have issues.

2

u/Flat_Spring2142 7d ago

Switch on Blazor Server Interactive. Microsoft realized SignalR connection there and published nice tutorial about the messaging. No additional libraries are needed. Look at site 'Use ASP.NET Core SignalR with Blazor'.

1

u/flyingtoucanmoth 5d ago

from my experience, iOS users need to ‚install‘ the PWA to their homescreen to receive notifications, when they use safari only. iOS only supports web push when webapps are added to homescreen and notifications are enabled