【发布时间】:2020-10-29 19:35:46
【问题描述】:
我创建了 Azure 通知中心,并将 Firebase 中的服务器密钥添加到通知中心的“GCM/FCM”部分。之后,我使用共享访问密钥和通知中心名称来创建安装(按照 Azure 文档)。这是我使用的代码:
[FunctionName("TestFunction")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
HttpRequest req, ILogger log)
{
var deviceUpdate = new DeviceInstallation()
{
installationId = "<myInstallationid>",
pushChannel = "<DeviceTokenGeneratedByFirebase>",
platform = "fcm",
tags = new string[] {"notificationhubtag1"},
};
var responseMessage = new HttpResponseMessage();
try
{
responseMessage = await Put(deviceUpdate);
}
catch
{
log.LogInformation("exception occured");
}
return new OkObjectResult(responseMessage);
}
// Custom API
public static async Task<HttpResponseMessage> Put(DeviceInstallation deviceUpdate)
{
NotificationHubClient hub = new NotificationHubClient(fullAccessConnString, hubName);
Installation installation = new Installation();
installation.InstallationId = deviceUpdate.installationId;
installation.PushChannel = deviceUpdate.pushChannel;
installation.Tags = deviceUpdate.tags;
switch (deviceUpdate.platform)
{
case "mpns":
installation.Platform = NotificationPlatform.Mpns;
break;
case "wns":
installation.Platform = NotificationPlatform.Wns;
break;
case "apns":
installation.Platform = NotificationPlatform.Apns;
break;
case "fcm":
installation.Platform = NotificationPlatform.Fcm;
break;
default:
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
await hub.CreateOrUpdateInstallationAsync(installation);
return new HttpResponseMessage(HttpStatusCode.OK);
}
public class DeviceInstallation
{
public string installationId { get; set; }
public string platform { get; set; }
public string pushChannel { get; set; }
public string[] tags { get; set; }
}
当我运行此代码时,我会收到一条成功消息。 Azure 门户本身并没有显示太多关于 no 的信息。 Azure 通知中心中注册的设备或活动设备信息。但是,我能够通过直接通过此调用向安装 API 发出 GET 请求来确认安装存在:
https://<myNotificationHubNameSpace>.servicebus.windows.net/<myHubName>/installations/<myInstallationId>/?api-version=2015-01
这个调用返回了一个 200 OK 我在前面步骤中创建的安装。响应如下所示:
{"installationId":"<myInstallationId>","pushChannel":"<DeviceTokenGeneratedByFireBase>","pushChannelExpired":false,"platform":"gcm","expirationTime":"9999-12-31T23:59:59.9999999Z","tags":["notificationhubtag1"]}
所以,我去了 Azure 通知中心并从“测试发送”选项卡发送了一条测试消息,并在“发送到”标签字段中使用了“通知中心标签 1”标签。我收到了“通知已成功发送到推送通知系统”的成功消息,并且还获得了注册号。
但是,我没有看到任何通知被发送到应用程序本身。如何调试有关正在推送的此特定消息的更多信息。推到哪里去了?
有没有办法在通知中心本身上找到有关推送消息、已安装设备等的更多信息?我发现一篇关于检查日志的旧帖子说要切换到标准层而不是免费层以获取更多信息。我已切换到标准层,但我看不出在免费层或标准层之间向我显示概览或活动日志的方式有任何差异。
【问题讨论】:
标签: azure push-notification firebase-cloud-messaging azure-notificationhub