:::: MENU ::::

Sending push notification to iOS from ASP.Net MVC Core

In a project that i am currently working, i need to send push notification to iOS client app. I have never done that before so, first i did a quick google search and find this SO question. His requirement is for .Net framework so i need to tweak few things to make it functional in .Net Core. So here is how I made it work with .Net core.

Get .p12 or .pfx certificate from your apple developer account so your server side code can connect with APNS Server. Also get your Device Id so that you can deliver push notification in that device. You can convert .p12 certificate to .pfx by just changing extension.

Now in ASP.Net:

There are two helper methods after this method which you can find inside sample project in github. I don’t have to explain much here it is pretty straight forward. But few tweaks that i made are:

  • Implemented new TCPClient API. Look more about TCPClient in Corefx repo.
  • Change in getting certificate path. (No System.web in core)
  • SslStream got Async for AuthenticateAsClient method. i.e. AuthenticateAsClientAsync
  • TCPClient object is now disposed using Dispose method.

Quick Note: If you are are hosting your application in azure then upload .pfx (not .p12) certificate in your azure site. Here is a quick tutorial for that.

That’s it. Now its your job to manage this code as per your requirement. Here is output in iOS.

Sample is in github.

Happy Coding 🙂