iOS, Objective-C, Swift, Design and Whatever Comes in Mind
‹ Back to the Blog

Open Source Project: Go-APNS

I learned a new programming language. On purpose.
For a long time, I wanted to write a client for Apples push notification system. APNS stands for 'Apple Push Notification System' and is responsible for delivering push notification to devices. The developers job is to aquire a device token from the device you want to push to and then send a request to APNS with the notification you want to push.

Last year, Apple introduces their second version of this API that replaced their binary interface in favor of HTTP2.

That is where Go-APNS comes into play: it lets you create and perform such a request easily.
I wrote detailed documentation on the project site but I want to highlight a few features here.

After you have created a Connection object by passing the path to your certificate as well as the keyphrase, you have completed the first step.

Now, the handy features of Go-APNS comes into play: it is very easy to construct the message you send to Apple. The documentation split it into two major parts: Header and Payload, which includes the Alert.

message := goapns.NewMessage().Title("Title").Body("A Test notification :)").Sound("Default").Badge(42)
message.Custom("customKey", "customValue")

Now you are ready to send them to APNS. Take the Connection you created in the first step and call conn.Push(message, tokens, responseChannel). You pass in the device token to which the notification should be sent to and a responseChannel which is a chan. Due to the fact, that the requests are performed asynchronously, the results are passed into this channel.
You get a Response object delivered in which a possible error is stored.



It was fun to learn a new language (Go) and tackle a problem that I wanted to address for a long time. Two weeks ago I started the beginner tutorial and now, I can release my first Golang project.
That beeing said, I invite you to try it out. As always, I appreciate every kind of feedback :)
Once again, here is the link to GitHub.

"Open Source Project: Go-APNS".