Home > ASP.NET > IPhone Push Notification from ASP.NET C# Moon APNS

IPhone Push Notification from ASP.NET C# Moon APNS

Consider a scenario, I need to send a push notification to IPhone when I add a new card (card id and card name) at back end(from ASP.NET C# Web application)

At First, reference these Moon APNS dlls.


Try the code below, it fetches all the iphone device ids from table, and send message to each devices.

internal void SendPushNotificationIPhone(int CardId, string CardName, string Path)




DataTable tab = datalogic.GetDeviceTokens(); // Getting all device ids from the table

var p = new List<NotificationPayload>();

for (int i = 0; i < tab.Rows.Count; i++)


string message = “Card Added”;

var payload = new NotificationPayload(tab.Rows[i][0].ToString(), message, 1, “default”);

payload.AddCustom(“ID”, CardId);   // Custom fields as id and card name

payload.AddCustom(“CardName”, CardName);



var push = new PushNotification(true, Path, “password”);

//path is iphone app’s p12 certificate file, put password for that certificate also,

var rejected = push.SendToApple(p);  // error list

foreach (var item in rejected)






catch (Exception ep)


//  Error



Categories: ASP.NET
  1. June 17, 2013 at 11:07 pm

    Hi, I’m getting an error message “A call to SSPI failed, see inner exception.” while executing _apnsStream.AuthenticateAsClient, inside the OpenSslStream method.

    Since it’s inside in a try/catch section, afterwards, when it tries to execute _apnsStream.BeginRead it produces an innerexeption “uknown error while processing the certified”

    Could you please help me out to figure out what’s the problem?

    • June 23, 2013 at 5:31 pm

      Hi Salazar,
      I think the certificate file is incorrect. I faced some problem when i first tried because i got an incorrect certificate from the iPhone developer.

  2. Abdelrahman Nafea
    December 19, 2013 at 11:21 am

    hi, i get the Empty list from the rejected

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: