IOS notifications are not sent using PushSharp. The event is not raised either

I am trying to use PushSharp to send notifications to various devices. The server-side application registers notifications for sending to the table in MSSQL, so another application (Bot) will process these notifications and send them to Apple servers.

I am using the following code:

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

As you can see, I am notifying the queue in PushBroker, but no events are triggered and the iOS device does not receive anything. I also tried to use "StopAllServices" until the end of the cycle, but nothing changed.

How is this possible?

Thank.

+3
source share
1 answer

. PushSharp , , . :

    PushBroker broker = new PushBroker();
    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;
    // Now you can register the service.
    broker.RegisterAppleService(new PushSharp.Apple.ApplePushChannelSettings(false, appleCert, "XXXXX"));
+9

All Articles