我一直在尝试从我的Xamarin Android项目注册NH。我设法配置FireBase,但当我尝试在客户端注册Notification Hub时,我收到了未经授权的异常。我确信我已经使用了正确的连接凭证,因为我在UWP项目中使用了相同的凭证,它在那里工作。
这是我的代码:
Hub = new NotificationHub(Constants.NotificationHubName, "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=mykey=",
context);
try
{
Hub.UnregisterAll(registrationId);
}
catch (Exception ex)
{
Log.Error(MyBroadcastReceiver.TAG, ex.Message);
}
var tags = new List<string>() { "droid" }; // create tags if you want
// var tags = new List<string>() { };
try
{
var hubRegistration = Hub.Register(registrationId, tags.ToArray());
}
catch (Exception ex)
{
Log.Error(MyBroadcastReceiver.TAG, ex.Message);
}
我从UnregisterAll和Register两种方法中获得了未经授权的异常。请任何建议,如何解决这个问题。
答案 0 :(得分:0)
表示您的通知中心凭据错误或无效。您能否确保您引用了正确的通知中心和相应的连接字符串。
旁注,您无需调用取消注册api。 Register API充当CreateOrUpdate。如果不存在,它将负责创建注册。
答案 1 :(得分:0)
由于您提到通过MobileServiceClient工作,您可以通过App Service Push注册。查看http://aka.ms/zumobook - 第5章。这包括有关如何注册标记的每个平台的代码。