:::: MENU ::::

Sending push notification to iOS from ASP.Net MVC Core

In a project that I am currently working, I need to send a push notification to the 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 the 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 on that device. You can convert .p12 certificate to .pfx by just changing the extension.

Now in ASP.Net:

There are two helper methods after this method which you can find inside sample project on 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 it’s your job to manage this code as per your requirement. Here is output in iOS.

The sample is on GitHub.

Happy Coding 🙂