【发布时间】:2018-11-19 21:07:51
【问题描述】:
我目前有一个移动应用程序通过 Azure 中的通知中心和 Web API 后端接收推送通知。我想为 iOS 执行应用程序测试,并将辅助通知中心设置为开发,以便注册用户不会收到来自我的测试的通知。
在 Azure 门户上,我看到后端与当前为 Apple APNS 设置为生产的通知中心相关联,如下图所示。
在移动应用程序中,在 Xamarin iOS 项目中,与后端的注册如下:
async Task SendRegistrationToServerAsync(NSData deviceToken)
{
//this is the template/payload used by iOS. It contains the "messageParam"
// that will be replaced by our service
const string templateBodyAPNS = @"{
""aps"" : {
""alert"" : ""$(messageParam)"",
""mutable-content"": 1
},
}";
var templates = new JObject();
templates["genericMessage"] = new JObject
{
{"body", templateBodyAPNS }
};
// send registration to web api
// MobileServiceUrl points to the Web API mentioned above
var client = new MobileServiceClient(MyMobileAppName.App.MobileServiceUrl);
await client.GetPush().RegisterAsync(deviceToken, templates);
//get the installation id
Console.WriteLine("Installation id1: " + client.InstallationId.ToString());
}
问题是:
- 在 Application Settings 中,我可以添加另一个 HubName 和 HubId(以分离开发和生产),并在 Connection strings 中为其添加关联的第二个连接字符串。将注册上面代码行中的 Web API 会根据应用程序运行的环境自动检测哪个集线器正在开发中,哪个集线器正在生产中?
或是否会因为将两个集线器与同一个 Web api 关联而出错,并且应用程序将无法正常运行?
【问题讨论】:
标签: azure push-notification xamarin.ios apple-push-notifications