我正在使用Azure通知中心,并且我想向.NET后端中的所有注册设备发送推送通知消息。但我不确定这种方式会发送到所有设备,因为我没有办法检查收到推送消息的设备数量。 那么,怎么样,我可以发送推送消息给所有设备,或者可以确保这种方式是正确的?使用.NET向Azure通知中心的所有注册设备发送推送通知
public static async Task<bool> SendBroadcast(string msg)
{
try
{
var notificationHubClient = NotificationHubClient.CreateClientFromConnectionString(ConfigurationManager.AppSettings["ServiceBusPushNotificationConnectionString"], ConfigurationManager.AppSettings["ServiceBusPushNotificationName"]);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("message", msg);
param.Add("alert", msg);
var template = new TemplateNotification(param);
var result = await notificationHubClient.SendNotificationAsync(template);
Console.WriteLine(JsonConvert.SerializeObject(result));
return true;
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
return false;
}
}
小记,'result'是具有支撑型'NotificationOutcome'的'Failure'和道具'Success'类型都是长。所以你回归真实,虽然它可能是错误的(失败)? –