【发布时间】:2018-04-01 16:47:29
【问题描述】:
谁能帮助我使用 Azure 通知中心,如何设置设备安装表单 c# 代码。我对 Installation 对象有疑问。如何将其设置为将其作为参数传递给中心客户端实例的 CreateOrUpdateInstallation 方法。我不清楚。
我在 azure 上有一个集线器,可以在本地进行设备注册,如魅力,但上传到 azure 上不起作用。现在我想尝试一下。
thnx
更新:4 天后,我发现您无法向自己发送通知。 Azure 不知何故知道您正在向您的手机发送通知,这就是为什么我的欢迎消息从未发送到我的手机。
更新:这就是我现在在后端代码中安装设备的方式:
[HttpGet]
[Route("api/push/test-installation")]
public async Task<IActionResult> NotificationInstalationTest()
{
string connectionString = "{{my connection string}}";
string hubName = "{{my hub name}}";
string token = "{{tokne}}";
NotificationHubClient hubClient = NotificationHubClient.CreateClientFromConnectionString(connectionString, hubName);
string notificationText = $"Test message for Azure delivery for Atila at: {DateTime.Now.ToShortTimeString()}";
var alert = new JObject
(
new JProperty("aps", new JObject(new JProperty("alert", notificationText))),
new JProperty("inAppMessage", notificationText)
).ToString(Newtonsoft.Json.Formatting.None);
IList<string> tags = new List<string>();
tags.Add("email");
IDictionary<string, string> pushVariables = new Dictionary<string, string>();
pushVariables.Add( "email", "atila@panonicit.com" );
Installation installation = new Installation();
installation.InstallationId = Guid.NewGuid().ToString();
installation.Platform = NotificationPlatform.Apns;
installation.PushChannel = token;
installation.Tags = tags;
installation.PushVariables = pushVariables;
await hubClient.CreateOrUpdateInstallationAsync(installation);
NotificationOutcome result = await hubClient.SendAppleNativeNotificationAsync(alert);
return Ok("Success");
}
现在,当我使用 Postman 访问此端点时,它可以工作,如果来自 iOS 的相同端点调用它不起作用!
thnx
【问题讨论】: