使用 signalR 向 .net Maui 中的特定用户和组发出通知

问题描述 投票:0回答:1

如何按组向特定用户发送通知?我唯一的工作代码适用于所有移动用户。

我能够从控制台发送通知

await hubConnection.InvokeAsync("SendMessage", "Sample notification.");

我的中心:

public async Task SendMessage(string message)
{
    await Clients.Others.SendAsync("ReceiveMessage", message);
}

毛伊岛后台服务:

 hubConnection.On<string>("ReceiveMessage", (message) =>
            {
                // Display the message in a notification
                BadgeNumber++;
                notification.SetNumber(BadgeNumber);
                notification.SetContentTitle(message);
                StartForeground(myId, notification.Build());
            });
signalr maui signalr.client
1个回答
0
投票

在我的应用程序中,消息发送者在消息中包含组 ID。聊天中心从消息中提取群组 ID 并将其发送到请求的群组:

等待 Clients.Group(group).SendAsync("MessageReceived", message);

大多数消息都会发送给群组中的每个人。但我确实在发送给单个收件人的消息中包含了 ID 字段,而这些消息会被其他人忽略。

© www.soinside.com 2019 - 2024. All rights reserved.