apple push notification with APNS sharp

10,360

Solution 1

i found out the problem. it was error in APNS SHARP library thread workflow.

EDIT:
i am calling this method after queueing all the notification.
like
service.start();
and here is method

     public void Send()
    {
        foreach (NotificationConnection conn in this.notificationConnections)
        {
           // Console.Write("Start Sending");
            conn.start(P12File, P12FilePassword);
        }
    }

Solution 2

I am seeing this as well. Looking at the NotificationConnection.Close() method i found this:

// Sleep here to prevent a race condition // in which a notification could be queued while the worker thread // is sleeping after its loop, but if we set closing true within that 100 ms, // the queued notifications during that time would not get dequeued as the loop // would exit due to closing = true; // 250 ms should be ample time for the loop to dequeue any remaining notifications // after we stopped accepting above Thread.Sleep(250);

And in the loop mentioned i found: Thread.Sleep(500);

Setting the sleep time in the close method to 1000 fixed it for me ;) - answer from :http://code.google.com/p/apns-sharp/issues/detail?id=41

Share:
10,360
Nnp
Author by

Nnp

enthusiastic developer.

Updated on June 04, 2022

Comments

  • Nnp
    Nnp almost 2 years

    i use APNS Sharp library for my apple push notification. i have downloded from Here.i use sample test program provided by APNS sharp library without any modification.
    it simply does not send any notification until i put break point at that line of code. if i put break point. i just work fine.is this expected behaviour or i am doing something wrong. and also i am not getting any exception. thanks for any help. here is the code

    static void Main(string[] args)
    {
        bool sandbox = true;
        string testDeviceToken = "Token";
        string p12File = "apn_developer_identity.p12";
        string p12FilePassword = "yourpassword";
        int sleepBetweenNotifications = 15000;
        string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
        NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);
        service.SendRetries = 5; 
        service.ReconnectDelay = 5000; //5 seconds
        service.Error += new NotificationService.OnError(service_Error);
        service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
        service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
        service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
        service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
        service.Connecting += new NotificationService.OnConnecting(service_Connecting);
        service.Connected += new NotificationService.OnConnected(service_Connected);
        service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
        Notification alertNotification = new Notification(testDeviceToken);
        alertNotification.Payload.Alert.Body = "Testing {0}...";
        alertNotification.Payload.Sound = "default";
        alertNotification.Payload.Badge = i;
        if (service.QueueNotification(alertNotification))
          Console.WriteLine("Notification Queued!");
        else
          Console.WriteLine("Notification Failed to be Queued!");
        Console.WriteLine("Cleaning Up...");
    
        service.Close();// if i dont put a break point in here, it simply does not send any notification
    
        service.Dispose();
    
    }
    

    i hope my question is clear...
    Update: i am stuck here.please any one can help me.