Search code examples
iphoneasp.netpush-notificationmoonapns

Unable to send push notification from server


I am working on an iPhone app which is using push notifications from a asp.net backend. I have used moon apns to send notifications. I was able to send the notifications when I executed the code on localhost but when I try to run the same code on server it doesn't send notifications.

I am using following code to send the notifications:

string message = string.Format("{0} has sent you a text chirp", username);
    var payload1 = new NotificationPayload(token, message, int.Parse(badgeNumber), "default");
    payload1.AddCustom("MessageType", "MessageTypeText");
    payload1.AddCustom("Sender", toFbID);
    payload1.AddCustom("AlertMessage", message);
    payload1.AddCustom("MessageID", msgid);

    var p = new List<NotificationPayload> { payload1 };

    var push = new PushNotification(true, "aps_development.p12", "chrip");

    var rejected = push.SendToApple(p);
    foreach (var item in rejected)
    {
        contxt.Response.Write(item);
    }

Edit

Just updated path of .p12 key, also the key is within the folder where the .net files are.


Solution

  • Try checking out PushSharp. https://github.com/Redth/PushSharp

    There's a wiki article on how to properly setup for sending push notifications, and of course the library itself makes it all easier too :)