【发布时间】:2017-03-08 23:40:03
【问题描述】:
我已成功实现了一个原型 Xamarin 表单应用程序,我将其部署到 Visual Studio (2015) 中的 Android 移动模拟器。 我使用 Google Cloud Messaging 作为本机通知服务,并且该应用程序一次性注册它从 GCM 接收到 Azure Notification Hub 的令牌。
到目前为止一切正常。
但是,在某些时候,我在构建客户端 NotificationHub 对象(使用称为 Azure 消息传递组件的 Xamarin 组件)的代码中不小心在我的 Azure 通知中心的名称中引入了一个流氓附加字符。
构造函数接受 3 个参数
- Azure 通知中心中定义的通知中心名称
- 监听连接字符串
- Android 上下文对象作为 GCMClient 握手的一部分传递到 OnRegistered 事件中
删除应用程序并在模拟器上重新部署它 - 如果我在第一个构造函数参数中放置了虚假的通知中心名称,则通知似乎成功并且设备会收到通知。这个参数只是调试所需的友好字符串吗?我已经让自己满意了,不正确的连接字符串会导致构造函数和注册失败。
这是我的 OnRegistered 方法代码,其意图服务用于处理通知的注册和后续接收。
protected override void OnRegistered(Context context, string registrationId)
{
Log.Verbose("PushHandlerBroadcastReceiver", "GCM Registered: " + registrationId);
RegistrationID = registrationId;
/** "NHub" is the hub name on Azure rather than bogus value of "NHub-"
In the real code I get this from Constants.HubName
but hardcoding here to highlight the issue of concern
**/
Hub = new NotificationHub("NHub-", Constants.ListenConnectionString, context);
try
{
Hub.UnregisterAll(registrationId);
}
catch (Exception ex)
{
Log.Error(MyBroadcastReceiver.TAG, ex.Message);
}
var tags = new List<string>() { };
try
{
string templateBodyGCM = "{\"data\":{\"message\":\"$(messageParam)\"}}";
var hubRegistration2 = Hub.RegisterTemplate(registrationId, "genericMessage", templateBodyGCM, tags.ToArray());
}
catch (Exception ex)
{
Log.Error(MyBroadcastReceiver.TAG, ex.Message);
}
}
任何人都可以确认 NotificationHub 对象的 API 调用是否只是将第一个参数用作调试/跟踪等的不透明字符串,并且它的值对于在 Azure 上设置 Notification Hub 事务(例如注册和接收)并不重要通知?
【问题讨论】:
标签: android azure xamarin xamarin.android xamarin.forms