我正在尝试将iOS设备注册到Azure通知中心
注册有效-不会引发任何错误。
调用lst = listview(listSource) {
cellFormat {
graphic = hbox {
textfield(it.name)
combobox(values=listOf(true, false)) {
value = it.flag1
}
combobox(values=listOf(true, false)) {
value = it.flag2
}
textfield(it.info)
}
}
}
可获得0条记录
发送测试消息将返回await _hub.GetAllRegistrationsAsync(0)
实施:
我有一个Message was successfully sent, but there were no matching targets.
类,用于注册设备。
AzurePushNotificationsService
我注册了设备:
public class AzurePushNotificationsService
{
private readonly NotificationHubClient _hub;
public AzurePushNotificationsService()
{
_hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=[endpoint]/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=[access_key]", "push_app_dev");
}
private async Task<string> RegisterDevice(string token)
{
string newRegistrationId = null;
if (!string.IsNullOrWhiteSpace(token))
{
var registrations = await _hub.GetRegistrationsByChannelAsync(token, 100);
foreach (var registration in registrations)
{
if (newRegistrationId == null)
{
newRegistrationId = registration.RegistrationId;
}
else
{
await _hub.DeleteRegistrationAsync(registration);
}
}
}
return newRegistrationId ?? await _hub.CreateRegistrationIdAsync();
}
public async Task<string> CreateOrUpdateRegistration(string token, DeviceType deviceType, string registrationId = null)
{
if (string.IsNullOrWhiteSpace(registrationId))
registrationId = await RegisterDevice(token);
RegistrationDescription registration = null;
switch (deviceType)
{
case DeviceType.Apple:
registration = new AppleRegistrationDescription(token);
break;
}
registration.RegistrationId = registrationId;
var registrationStale = false;
try
{
// throws no error.
registration = await _hub.CreateOrUpdateRegistrationAsync(registration);
}
catch (MessagingException e)
{
var webEx = e.InnerException as WebException;
if (webEx != null && webEx.Status == WebExceptionStatus.ProtocolError)
{
var response = (HttpWebResponse)webEx.Response;
if (response.StatusCode == HttpStatusCode.Gone)
{
registrationStale = true;
}
}
}
// if the registration is stale and/or removed then it needs to be re-created with a new registrationId
if (registrationStale)
registrationId = await CreateOrUpdateRegistration(contactId, token, deviceType);
return registrationId;
}
}
我发送了一条测试消息,并且得到消息:
string token = "9da952de6877b23738f5e744b6149750505417afc84d31290044643fa1493d2c".ToUpper();
var service = new AzurePushNotificationsService();
await service.CreateOrUpdateRegistration(token, DeviceType.Apple, null);
我想念的东西吗?