我正在尝试使用 PushSharp 向各种设备发送通知。我的服务器端应用程序注册通知以发送到 MSSQL 中的表,以便另一个应用程序 (Bot) 处理这些通知并将它们发送到 Apple 服务器。
我正在使用以下代码:
static DataEntities Entities;
static void Main(string[] args)
{
Entities = new DataEntities();
var appleCert = File.ReadAllBytes(Path.GetFullPath("My_Push_Notifications.p12"));
PushBroker broker = new PushBroker();
broker.RegisterAppleService(new PushSharp.Apple.ApplePushChannelSettings(false, appleCert, "XXXXX"));
broker.OnChannelCreated += broker_OnChannelCreated;
broker.OnChannelDestroyed += broker_OnChannelDestroyed;
broker.OnChannelException += broker_OnChannelException;
broker.OnNotificationRequeue += broker_OnNotificationRequeue;
broker.OnServiceException += broker_OnServiceException;
broker.OnNotificationSent += broker_OnNotificationSent;
broker.OnNotificationFailed += broker_OnNotificationFailed;
while (true)
{
var pendingNotifications = Entities.Notifications.Include("UserDevice").Where(n => n.Status == (byte)Constants.Notifications.Status.Pending);
if (pendingNotifications.ToList().Count > 0)
{
Console.WriteLine("Pending notifications: {0}", pendingNotifications.Count());
}
else
Console.WriteLine("No pending notifications");
foreach (var notification in pendingNotifications)
{
broker.QueueNotification<AppleNotification>(new AppleNotification()
.ForDeviceToken(notification.UserDevice.DeviceID)
.WithAlert(notification.Text)
.WithTag(notification.NotificationID));
notification.Status = (byte)Constants.Notifications.Status.Sending;
}
Entities.SaveChanges();
Thread.Sleep(2000);
}
}
如您所见,我将通知排队发送到 PushBroker,但从未调用任何事件,并且 iOS 设备什么也没有收到。我还尝试在循环结束之前使用“StopAllServices”,但没有任何变化。
这怎么可能?
谢谢你。