Azure Xamarin iOS推送通知在生产环境中不起作用,但在开发环境中可以正常工作
我有一个托管在Azure中的Web API。web API具有POST方法,当使用Postman将带有字符串正文的消息发布到web API url时,消息会在开发中完美地发送到移动设备。下面是它的代码:Azure Xamarin iOS推送通知在生产环境中不起作用,但在开发环境中可以正常工作,azure,xamarin.ios,apple-push-notifications,Azure,Xamarin.ios,Apple Push Notifications,我有一个托管在Azure中的Web API。web API具有POST方法,当使用Postman将带有字符串正文的消息发布到web API url时,消息会在开发中完美地发送到移动设备。下面是它的代码: [Authorize] [HttpPost, Route("send")] public async Task<NotificationOutcome> Post([FromBody]string message) {
[Authorize]
[HttpPost, Route("send")]
public async Task<NotificationOutcome> Post([FromBody]string message)
{
string hubName = "hubname";
string hubNameDefaultShared = "endpointAddress";
NotificationHubClient hub = NotificationHubClient
.CreateClientFromConnectionString(hubNameDefaultShared, hubName, enableTestSend: true);
string installationId = string.Empty;
var templateParams = new Dictionary<string, string>
{
["messageParam"] = message
};
NotificationOutcome result = null;
if (string.IsNullOrWhiteSpace(installationId))
{
result = await hub.SendTemplateNotificationAsync(templateParams).ConfigureAwait(false);
}
else
{
result = await hub.SendTemplateNotificationAsync(templateParams, "$InstallationId:{" + installationId + "}").ConfigureAwait(false);
}
return result;
}
[授权]
[HttpPost,路由(“发送”)]
公共异步任务发布([FromBody]字符串消息)
{
字符串hubName=“hubName”;
字符串hubNameDefaultShared=“endpointAddress”;
NotificationHubClient hub=NotificationHubClient
.CreateClientFromConnectionString(hubNameDefaultShared、hubName、enableTestSend:true);
string installationId=string.Empty;
var templateParams=新字典
{
[“messageParam”]=消息
};
NotificationOutput结果=null;
if(string.IsNullOrWhiteSpace(installationId))
{
结果=Wait hub.SendTemplateNotificationAsync(templateParams).ConfigureWait(false);
}
其他的
{
结果=await hub.SendTemplateNotificationAsync(templateParams,“$InstallationId:{”+InstallationId+“}”)。ConfigureAwait(false);
}
返回结果;
}
当我切换到生产并从应用商店下载应用程序时,使用Postman向上述Web API发布时,不会收到推送通知:
我已经完成的步骤:
关于通知中心,我需要对web API做些什么才能将其设置为生产?这些都是使用p12证书将通知中心设置为生产的步骤,还是我遗漏了什么?我想我已经找到了答案。问题似乎是我在开发模式下使用手机进行测试。我的手机已注册开发设备令牌。在生产模式下从应用商店下载应用程序时,该令牌不再有效,我的手机也不会收到通知。不知何故,我的设备与开发令牌保持关联,即使在删除了随Visual Studio安装的应用程序并从应用商店下载该应用程序之后 我在Azure文档网站的链接中找到了以下内容: “如果您的集线器最初配置了Apple沙盒证书,然后重新配置为使用Apple生产证书,则原始设备令牌无效。无效令牌会导致推送失败。请分离您的生产和测试环境,并针对不同的环境使用不同的集线器。”
因此,最好有两个通知中心,一个用于开发,另一个用于生产。我想我已经解决了。问题似乎是我在开发模式下使用手机进行测试。我的手机已注册开发设备令牌。在生产模式下从应用商店下载应用程序时,该令牌不再有效,我的手机也不会收到通知。不知何故,我的设备与开发令牌保持关联,即使在删除了随Visual Studio安装的应用程序并从应用商店下载该应用程序之后 我在Azure文档网站的链接中找到了以下内容: “如果您的集线器最初配置了Apple沙盒证书,然后重新配置为使用Apple生产证书,则原始设备令牌无效。无效令牌会导致推送失败。请分离您的生产和测试环境,并针对不同的环境使用不同的集线器。” 因此,最好有两个通知中心,一个用于开发,另一个用于生产