所以我写了一些测试发送代码,如下所示:
void TestSend(bool ios)
{
var AzureName = "myhubname";
var AzureHub = new ServiceBusConnectionStringBuilder("Endpoint=sb://secret+sauce").ToString();
var tags = new List<string>();
tags.Add("doopy");
try
{
var svcs = new ServiceBusConnectionStringBuilder(AzureHub).ToString();
var hub = NotificationHubClient.CreateClientFromConnectionString(svcs, AzureName);
// what is this?
// var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var installation = new Installation(); // control tag registration
// FCM - works
installation.Platform = NotificationPlatform.Fcm;
installation.PushChannel = "put my fcm token here";
installation.InstallationId = "see comment..."; // from the device via this call: myNotificationHub.Register(FCMToken, new List<string>().ToArray()).RegistrationId;
if (ios)
{ // silently fails
installation.Platform = NotificationPlatform.Apns;
installation.InstallationId = "some guid I made up";
installation.PushChannel = "see comment"; // device token with <> and spaces removed from call mySBNotificationHub.RegisterNativeAsync(deviceToken...
}
installation.Tags = tags;
hub.CreateOrUpdateInstallationAsync(installation).Wait();
JObject data = MakeNotification("notificationId", "I got your tags doopy!");
var payload = PlatformPayload(ios, data);
Console.WriteLine("Send...");
if (ios)
hub.SendAppleNativeNotificationAsync(payload, tags).Wait();
else
hub.SendFcmNativeNotificationAsync(payload, tags).Wait();
Console.WriteLine("Message SENT!");
}
catch (Exception ex)
{
Console.WriteLine("rats! " + ex.Message);
}
}
我什至不使用来自文档的神秘的PushNotificationChannelManager,并且FCM可以正常工作。该类似乎仅存在于UWP之内。
似乎APNS既需要安装ID,也需要频道,但我所拥有的只是设备ID。有人知道在哪里可以获取iOS的这些值吗?
答案 0 :(得分:0)
所以我找到了解决方案。
获取iOS设备令牌,删除空格和尖括号,然后将其用于PushChannel。创建您自己的InstallationId(Guid.NewGuid()。ToString();并将其保存在某个地方),或者仅将设备令牌用于两个字段。