Export to GitHub

apns-sharp - issue #57

Push Notification send only when i debug the code..issue


Posted on Feb 23, 2012 by Swift Monkey

i am having trouble using this library.i use JdSoft??.Apple.Apns.Notifications.Test for my testing. it just work fine in debug mode means i have to put break point in vs2008 otehrwise it wont work. any idea what could be wrong. if you have any idea then please tell me..

my code is as foollows

public bool SendNotification(string customheader, string customheaderValue, string DeviceTokenID, int BadgeCount) { try {

        bool sandbox = true;

        string testDeviceToken = DeviceTokenID;
        string p12File = "SynsoftGlobalApnsCertificates.p12";

        string p12FilePassword = "server";



        string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);

        NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);

        service.SendRetries = 5; //5 retries before generating notificationfailed event
        service.ReconnectDelay = 50000; //50 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);


            //Create a new notification to send
            Notification alertNotification = new Notification(testDeviceToken);

            //alertNotification.Payload.AddCustom("ordId", "NAA_949");
            alertNotification.Payload.AddCustom(customheader, customheaderValue);
            //alertNotification.Payload.Alert.Body = string.Format("NTO NAA_949");
            alertNotification.Payload.Alert.Body = string.Format("Visiting Card");
            alertNotification.Payload.Sound = "default";
            //alertNotification.Payload.Badge = 3;
            alertNotification.Payload.Badge = BadgeCount;

            //Queue the notification to be sent
            if (service.QueueNotification(alertNotification))
                Console.WriteLine("Notification Queued!");
            else
                Console.WriteLine("Notification Failed to be Queued!");

            //Sleep in between each message



        Console.WriteLine("Cleaning Up...");

        //First, close the service.  
        //This ensures any queued notifications get sent befor the connections are closed
        service.Close();

        //Clean up
        service.Dispose();

        Console.WriteLine("Done!");
        Console.WriteLine("Press enter to exit...");
        Console.ReadLine();
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
}

Comment #1

Posted on Feb 23, 2012 by Swift Monkey

and there is no any exception..occur please help me..

Comment #2

Posted on Feb 23, 2012 by Swift Monkey

Comment deleted

Comment #3

Posted on Mar 12, 2013 by Swift Monkey

I got the solution for that 1st check p12 file is correct and then you can check your code upload it on Production. my code is locally not work but when i upload this to server push notification is working for me.

Status: New

Labels:
Type-Review Priority-Medium