Sac*_*edi 7 azure ios asp.net-web-api azure-notificationhub
我正在关注此帖子以使用azure通知中心.我想要做的是创建web api,使用Azure通知中心注册设备.当我按照文章中所示发送注册设备的请求时,它会点击azure通知中心.
下面是我的天蓝色门户的屏幕截图.这表明有一个注册请求.
但是当我尝试使用以下代码获取已注册设备的详细信息时,它始终为0.
var registrationsCount = await hub.GetAllRegistrationsAsync(Int32.MaxValue);
return registrationsCount.Count().ToString();
Run Code Online (Sandbox Code Playgroud)
现在我几乎没有问题:
1)我如何探索注册设备的详细信息?
2)我如何从后端向ios设备发送测试通知.下面是我用来发送测试通知的代码.
var payload = string.Format(toastTemplate, message);
hub.SendAppleNativeNotificationAsync(payload, "worldnews");
Run Code Online (Sandbox Code Playgroud)
3)如果我使用web api作为后端,是否有必要在azure通知中心配置ios应用程序详细信息?即在天蓝色门户网站上传证书和其他详细信息?

Ala*_*SFT 20
你的第一个问题是如何打电话GetAllRegistrationsAsync.该参数不是您想要返回的最大注册数.这是您想要的第一次注册的索引.在大多数情况下,这将是0,而不是Int32.MaxValue
请参阅:https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.notificationhubs.notificationhubclient#Microsoft_Azure_NotificationHubs_NotificationHubClient_GetAllRegistrationsAsync_System_Int32_
public Task<CollectionQueryResult<RegistrationDescription>>
GetAllRegistrationsAsync(int top)
Run Code Online (Sandbox Code Playgroud)
另外,请记住,此方法最多返回100个注册.如果你想要更多,你需要使用ContinuationToken.
这是我用来获取注册的代码:
internal async Task<List<RegistrationDescription>> GetAllRegisteredDevicesAsync()
{
var hub = NotificationHubClient.CreateClientFromConnectionString(
Settings.Default.AzureNotificationsMobileAppFullSharedAccessListenerConnection,
Settings.Default.AzureNotificationsMobileAppHubName,
Settings.Default.AzureNotificationsTestSendMode);
var allRegistrations = await hub.GetAllRegistrationsAsync(0);
var continuationToken = allRegistrations.ContinuationToken;
var registrationDescriptionsList = new List<RegistrationDescription>(allRegistrations);
while (!string.IsNullOrWhiteSpace(continuationToken))
{
var otherRegistrations = await hub.GetAllRegistrationsAsync(continuationToken, 0);
registrationDescriptionsList.AddRange(otherRegistrations);
continuationToken = otherRegistrations.ContinuationToken;
}
return registrationDescriptionsList;
}
Run Code Online (Sandbox Code Playgroud)
请注意,仅当您只有几百个,可能是几千个注册时,才应使用此方法.如果您有数十,数十万或数百万的注册,则不应使用此方法,并找到更有效的方法来查找所需内容.
如果某个人只想获取已注册设备的详细信息而仅仅是为了不用于应用目的的知识,还有一种方法.Service Bus Explorer可用.您可以下载项目并将其解压缩并使用visual studio运行.
您可以通过提供连接字符串和所有者密钥来连接到azure服务.我用它来查看已注册的设备并发送测试通知等.这是一个非常有用的工具.
希望这可以帮助一些人.
| 归档时间: |
|
| 查看次数: |
5974 次 |
| 最近记录: |