Я разработал приложение с Xamarin Forms и реализовал уведомление pu sh с помощью Azure Notification Hub. Я следовал этому руководству с сайта Microsoft: https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-backend-service-xamarin-forms Я получаю уведомление, когда отправляю его всем. Проблема в том, что я использую «Тег», чтобы отправить его указанному пользователю c (я регистрирую этого пользователя с помощью определенного тега, когда он входит в приложение.) Это не работает, и я даже не знаю, как проверить, в чем проблема. Я пытался проверить погоду, тег назначен неправильно или не назначен вообще, но проверить это невозможно. Что я должен делать? Как я могу увидеть все теги, которые у меня есть в системе, и кто на них зарегистрирован? Возможно, я неправильно понял, но я не создаю тег перед регистрацией пользователя, я просто добавляю его в список тегов, когда пользователь регистрируется в системе.
public class DeviceInstallation
{
[Required]
public string InstallationId { get; set; }
[Required]
public string Platform { get; set; }
[Required]
public string PushChannel { get; set; }
public IList<string> Tags { get; set; } = Array.Empty<string>(); //Generate tag when register device and add it to list
}
public async Task RegisterDeviceAsync(params string[] tags)
{
var deviceInstallation = DeviceInstallationService?.GetDeviceInstallation(tags);
if (deviceInstallation == null)
throw new Exception($"Unable to get device installation information.");
if (string.IsNullOrWhiteSpace(deviceInstallation.InstallationId))
throw new Exception($"No {nameof(deviceInstallation.InstallationId)} value for {nameof(DeviceInstallation)}");
if (string.IsNullOrWhiteSpace(deviceInstallation.Platform))
throw new Exception($"No {nameof(deviceInstallation.Platform)} value for {nameof(DeviceInstallation)}");
if (string.IsNullOrWhiteSpace(deviceInstallation.PushChannel))
throw new Exception($"No {nameof(deviceInstallation.PushChannel)} value for {nameof(DeviceInstallation)}");
await SendAsync<DeviceInstallation>(HttpMethod.Put, RequestUrl, deviceInstallation)
.ConfigureAwait(false);
var serializedTags = JsonConvert.SerializeObject(tags);
await SecureStorage.SetAsync(CachedTagsKey, serializedTags);
}
На сервере есть следующий код:
public async Task<bool> CreateOrUpdateInstallationAsync(DeviceInstallation deviceInstallation, CancellationToken token)
{
if (string.IsNullOrWhiteSpace(deviceInstallation?.InstallationId) ||
string.IsNullOrWhiteSpace(deviceInstallation?.Platform) ||
string.IsNullOrWhiteSpace(deviceInstallation?.PushChannel))
return false;
var installation = new Installation()
{
InstallationId = deviceInstallation.InstallationId,
PushChannel = deviceInstallation.PushChannel,
Tags = deviceInstallation.Tags
};
if (_installationPlatform.TryGetValue(deviceInstallation.Platform, out var platform))
installation.Platform = platform;
else
return false;
try
{
await _hub.CreateOrUpdateInstallationAsync(installation, token);
}
catch
{
return false;
}
return true;
}