Receiving chat messages with SignalR

Stesvis 1,041 Reputation points
2021-01-23T01:29:59.907+00:00

I tested the SignalR solution in Xamarin Forms and .net core backend and it works great:
https://montemagno.com/real-time-communication-for-mobile-with-signalr/

However, I am wondering how to keep receiving the messages when the app is in background mode, as this solution (in the link) only works when you have the app open on the chat page....
Do I need to implement my own push notifications? If that is the case it defeats the purpose of SignalR so I hope there is another way that I haven't found yet :)

Thanks

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,317 questions
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
717 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ángel Rubén Valdeolmos Carmona 586 Reputation points
    2021-01-26T09:12:05.267+00:00

    There is a solution to address this problem:

    Since signalR disconnects when the app goes to the background and some time passes. The OnResume and OnSleep events are where you have to do all the magic. When it goes to OnSleep it disconnects SignalR and when you return to OnResume you reconnect it and check the new messages.

    1 person found this answer helpful.
    0 comments No comments

  2. Mouad Cherkaoui 6 Reputation points
    2021-01-25T09:04:39.197+00:00

    Hi Stesvis-5434,

    in fact it is possible to receive messages in background mode, all you need is whether a Background Worker for UWP apps :
    https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=net-5.0

    or another example is Service Workers in PWA :
    https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps-chromium/serviceworker

    it depend more on the platform you are using, for example here is an article about creating an Android service using xamarin:

    https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/services/creating-a-service/

    Hope it helps!

    Best Regards.