Make your own APNS pusher 🔔 through command-line

Sending normal APNS notification, Silent notification, Notification with mutable content using script files.

Apple Push Notification service (APNs) is the centerpiece of the remote notifications feature. It is a robust, secure, and highly efficient service for app developers to propagate information to iOS (and, indirectly, watchOS), tvOS, and macOS devices.

APNS notificaiton

In the development process or while debugging notification related stuff we need to send notification multiple times to a device.

We can do this through our application flow itself or through any third-party application. Most developers would be using Pusher App. One of the finest tools with simple UI. Kudos for the developer 🙌

It has some limitations such as the app comes with only two payload headers apns-expiration and apns-priority. If you want to try out some other headers like apns-collapse-id you have to go back to your backend developer and request to change the payload and deploy it.

Getting logs in Pusher App is limited. While debugging notification failures logs while connecting to APNS service and while sending payload is most important

To sort it out we gonna create out own executable file that sends a notification to the device simply by hitting enter in terminal. And another primary reason to use executable file is its fun to work with scripts and terminal commands. It feels like dealing with rocket science 🚀

  • Application Bundle identifier
  • APNS certificate in .pem format
  • Hexadecimal APNs device token
  • An iOS device
  • Importantly zero programming knowledge

cURL is a computer software project providing a library and command-line tool for transferring data using various network protocols. The name stands for “Client URL”, which was first released in 1997.

I’m using curl version 7.48.0,

-d, — data <data>: Sends the specified data in a POST request to the HTTP server

-H, — header <header/@file>: Extra header to include in the request when sending HTTP to a server

— http2 : (HTTP) Tells curl to use HTTP version 2.

— cert <certificate[: password]>: Tells curl to use the specified client certificate file when getting a file with HTTPS

To know more about curl commands visit https://curl.haxx.se/docs/manpage.html

Entering this curl in the command-line tool will send a notification to the device, but editing the payload, certificate path, header or device token is difficult in a terminal so we are going to make it as an executable .sh file

Create an .sh file

Add any one sample payload inside the script file

  1. Normal notification

2. Silent Notification

3. To trigger notification extension

Making apns_script.sh executable

run apns_script.sh

Yeah, we made it our executable file is ready. It can be modified and executed in a matter of seconds.

Think + Plan + Execute