• Michael Craun

Push Notification: Getting Started


Note from The Minimalist Programmer: Hello readers! Since I am not the only one at The Minimalist Programmer I would like to invite you to check out the About Us page on the website to become familiar with the author of this post. Please feel free to go and check out his website as well. But enough from me, back to the lesson.

Good morning, fellow code junkies! Over the next few weeks, I'll be doing a series of blog posts concerning Apple Push Notification service (APNs). My hope is that this series will alleviate some of the frustration that I have experienced in recent days in my attempts to get push notifications to work exactly the way I want them to.

Note: This series will assume you're already relatively comfortable with how Xcode works and you're already familiar with certain things like creating a new project and AutoLayout. If you aren't, please, continue reading or bookmark these pages for future reference. If you have any questions about the information detailed here, feel free to comment below. I'll be happy to answer any questions!

In an effort to keep the posts short, each post will cover a different topic. Today's topic will be how to get your project set up to send and receive push notifications. This isn't overly complicated, but can be tricky, if you aren't used to it. So, get comfortable and read on!

PROJECT

After creating a new project, there are only a few more steps you need to follow to get your app ready to send and receive push notifications. Firstly, enabling push notifications in your project's capabilities.

Above, you can see that I've created a new project named Alertable. In the Capabilities tab of the Alertable target, I've switched Push Notifications to "ON". Congratulations, you've completed the first step on your way to enabling your app to send notifications to your users!

Warning: Before continuing, you must have set up your App ID on your developer portal. This series isn't designed to cover that, so it won't be, but there are other guides on doing so!

DEVELOPER PORTAL

Now, head on over to developer.apple.com, log in, select Certificates, Identifiers & Profiles and add a new certificate by clicking the + button in the top, right-hand corner of the screen. If you're expecting to produce the app you're working on to the App Store, select the option titled "Apple Push Notification service SSL (Sandbox & Production)." Otherwise, select the option for just Sandbox. Then, scroll down to the bottom of the page and click "Continue".

I'm going to select the option for Sandbox only, as this project is for you guys, and you guys alone. The steps for production are the same, you just have to do them an extra time.

On this next screen, select the App ID that corresponds to the app you're working on and click Continue. The next screen informs you on how to generate a CSR file to upload to Apple. To do this, we need to open Keychain Access, so please do so on your Mac.

KEYCHAIN ACCESS

In Keychain Access, select Keychain Access > Certificate Assistance > Request a Certificate From a Certificate Authority... to display the Certificate Assistant and fill out the form, filling in:

  • Your email address for User Email Address

  • Your full name for Common Name

  • Select Saved to disk for Request is:

Click continue and save the generated file wherever you would like.

DEVELOPER PORTAL

Coming back to your developer portal, click "Continue" then click "Choose File..." Once you've selected your file and it has uploaded to Apple, click "Continue" and you should be presented with a download screen. Click "Download" and open the file to add it to your Keychain Access.

PROJECT

Go back to your project and you should see a brand new file that was automatically generated by Xcode: "YourProjectsName.entitlements"Congratulations, you've completed the necessary setup to start sending and receiving push notifications using APNs!

I know this was a lot of text and not a lot of code, and I apologize for that, but next week, this series will continue with getting a basic notification to appear on a user's device, which will include quite a bit of the good stuff! Stay tuned, code junkies!

#APNs #Notifications #Swift #iOS #Beginner

4 views0 comments

Recent Posts

See All

Week 2 - Getting Help

put your faith in God. I know it seems easy, cliche even, or perhaps you don’t see how that can help with the situation.