Skip to main content

Add iPhone push notification using ASP.NET server



Here's the overview.





I need to add push notification to an iPhone app. Server side is ASP.NET in c#.





What I would like is some coaching to work through the process. I will then post generic code for an iPhone project and an ASP.NET web app along with step-by-step instructions so that others can learn.





Here is my understanding:





  1. Apply for APNS certificate and add it to keychain. (Not sure how to bring this to ASP.NET)



  2. Have iPhones register with registerForRemoteNotificationWithTypes, send the value to your server, and store in a DB. Seems like this code to register should be easy but I can't find a good sample. (No problem with sending the value to the ASP.NET server.)



  3. Your server app creates a payload string, does JSON encoding, sends to the APNS server for each (or can it be for groups) of iPhones using their device token that was saved into the DB.







So to develop the addition, here are the pieces:









  • The iPhone registration code









  • Code that sends iPhone registration code to server and saves to DB (this is easy and I already have these pieces).









  • The server side APNS contact code in c#. This also includes how to use the certificate that was generated on the Apple Developer web site.









  • Also, can the payload be a multiple choice question that can be answered with the result sent back to the server?









Thanks in advance for the help. I will turn this in to a tutorial for others.


Comments

  1. So for the C# push part theres an open source project which you can use, its easy and has some sample code of how to use the libraries in order to send push notificaitons here is a link C# push notification project

    Basically all you gotta do is get the push certificate from apple, then drop it in your project and open it in the C# project (you can view the example and where to do it will be obvious)...

    The iphone part of pretty trivial and there are tons of examples out there

    ReplyDelete
  2. check here, Its a step by step guide for sending apple push notification with Asp.net and C#
    http://arashnorouzi.wordpress.com/2011/03/31/sending-apple-push-notifications-in-asp-net-part-1/

    ReplyDelete
  3. This took me forever to figure out but I finally pieced it all together from the minor clues people left. You need to download the certificate for the APPID that you register on the developer portal. That certificate must be converted into a P12 format to be used on Windows. These commands in UNIX finally did it for me:

    Step 1:

    openssl x509 -in aps_developer_identity.cer -inform DER -out aps_developer_identity.pem -outform PEM}


    Where aps_developer_identity.cer is the file you download from the portal

    Step 2:

    openssl pkcs12 -nocerts -out APSCertificates.pem -in APSCertificates.p12


    Where APSCertificates.p12 is a file you export from the Mac Keychain. This is critical, you must import the certificate from the portal into keychain. Find it in My Certificates, open the disclosure triangle and highlight both the certificate and the private key, then right click and export them. Give them a password and save them to a p12 file.

    Step 3:

    openssl pkcs12 -export -in aps_developer_identity.pem -out aps_developer_identity.p12 -inkey APSCertificates.pem


    You will be prompted a few times for the password you used to export the certificate and private key in Keychain and prompted again for new passwords to re-encrypt it all, but in the end you will have the file aps_developer_identity.p12 which you need to move to windows, then import it into both the Personal and Trusted Root sections of certificate manager in MMC. Then in C# when you use MoonAPNS and call the PushNotification class you give it a path to that certificate. Also make sure to remove spaces from the device token.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.