gpt4 book ai didi

ios - Azure 通知,注册设备服务器端。适用于 FCM 但不适用于 APNS 的通知

转载 作者:行者123 更新时间:2023-11-29 13:55:14 28 4
gpt4 key购买 nike

我正在关注本教程:https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management

所以我写了一些测试发送代码,如下所示:

  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);
}
}

我什至不使用文档和 FCM 作品中神秘的 PushNotificationChannelManager。那个类好像只存在于UWP什么的。

APNS 似乎需要安装 ID 和 channel ,但我只有设备 ID。有人知道哪里可以获取 iOS 的这些值吗?

最佳答案

所以我找到了解决方案。

获取 iOS 设备 token ,删除空格和尖括号并将其用于 PushChannel。创建您自己的 InstallationId(Guid.NewGuid().ToString();并将其保存在某处)或仅对这两个字段使用设备 token 。

关于ios - Azure 通知,注册设备服务器端。适用于 FCM 但不适用于 APNS 的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56860748/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com