Member-only story

Sending Apple Push Notifications from a .Net Core application

Paolo Montalto
2 min readJul 2, 2019

--

Push notifications

Recently I’ve come across the need for sending Apple Push Notifications from a REST Api I made with .Net Core.

You’ll se that’s pretty simple, what you will need is:

  • A valid apple developer account subscription
  • APNS certificates exported as a .p12 file via your developer account
  • A web server capable of outbound traffic on the 2195 port

Let’s assume you have an Apple developer account and you already created .p12 push certificate, here follows what you’ll need to do in your C# code.

First of all you will have to create a TCP client to connect to the Apple Push Notifications Services and instantiate an SslStream from that client

var hostname = "gateway.sandbox.push.apple.com";
var port = 2195;
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null
);

if you connect to the production environment the hostname will be “gateway.push.apple.com”.

I defined the certificate validation callback as follows

private bool ValidateServerCertificate(object sender, X509Certificate…

--

--

Paolo Montalto
Paolo Montalto

Written by Paolo Montalto

Android Engineer, freelance, mobile developer, software craftsman, guitar strummer, husband, father, humble.

Responses (2)