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,375 questions
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
777 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Ángel Rubén Valdeolmos Carmona 591 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.


  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Bruce (SqlWork.com) 70,376 Reputation points
    2025-01-30T16:44:19.51+00:00

    Signal/r will not work when the mobile app is not active. The server can log messages, and the mobile app can ask for a replay of messages it missed when it becomes active. as mobile internet connections are flaky, you will need this feature even when active.

    If you want mobile o/s to notify the user when there is activity, then you want use the mobile o/s notification services.

    note: even with a PWA most browsers will shutdown the websocket connection if the PWA is not the active tab.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.