Home > Uncategorized > Send #APNS #Push notifications using #RapidAPI

Send #APNS #Push notifications using #RapidAPI

TLDR; Go Here: https://rapidapi.com/dananos/api/simplified-apns-apple-push-notification-service

This is a simple tutorial to send an APNS (Apple Push Notification Service), to production using C# (RestSharp) and Rapid API. It uses HTTP/2, so will continue to work after the March 31st deadline.

To do this, you will need:

  • The P12 production certificate, and it’s password
  • An APNS token of an iOS app, that has subscribed to push notifications.
  • A subscription Key to this RapidAPI service.

Create a new project in Visual Studio, and add your p12 certificate to the project. Change it’s build properties to “copy always”.

From the Package management panel, Install Rest Sharp via Nuget with “Install-Package RestSharp”

Add the following code;

public static string Push(string destination, string message, string certFile, string certPassword, string rapidApiKey)
        {
            var certificate = File.ReadAllBytes(certFile);
            var client = new RestClient("https://rapidapi.p.rapidapi.com/Prod");
            var request = new RestRequest(Method.POST);
            request.AddHeader("x-rapidapi-key", rapidApiKey);
            request.AddHeader("x-rapidapi-host", "simplified-apns-apple-push-notification-service.p.rapidapi.com");
            request.AddJsonBody(new
            {
                destination,
                message,
                certificate,
                certPassword
            });
            var response = client.Execute(request);
            return response.Content;
        }

The calling code will be up to you, but it will be in the form;

        var destination = "8ec378164725d019fce12c420cea7......";
        var message = "hello, this is rapidAPI!";
        var certPassword = "XXXXX";
        var certFile = "XXXXX.p12";
        var rapidApiKey = "PUB#XXXXXXXX";
        var pushResponse = Push(destination, message, certFile, certPassword, rapidApiKey);
        Console.WriteLine(pushResponse);
Categories: Uncategorized
  1. No comments yet.
  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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: