Heads up... You're reading this book for free, with parts of this chapter shown beyond this point astext.
You can unlock the rest of this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.
Push notifications are a useful feature that allow you to interact with your users outside of the normal flow of your app. A notification can be scheduled locally based on conditions such as time or location, or scheduled from a remote service and “pushed” to your device. Regardless of whether you are utilizing a local or remote notification, the general process for handling one is the same:
- Ask your user for permission to receive notifications.
- Optionally make changes to the message before display.
- Optionally add custom buttons for the user to interact with.
- Optionally configure a custom user interface to display the notification.
- Optionally take action based on what the user did with the notification.
What are they good for?
You’d be hard pressed in this day and age to not have seen a push notification at some point. They are capable of many actions:
- Displaying a message.
- Playing a sound.
- Updating the badge icon on your app.
- Showing an image or playing a movie.
- Giving the user a way to pick from a few options.
Anything that a
While you can technically show any type of user interface as long as it fits within the bounds of a notification window, that doesn’t mean you should do so. Always keep user experience in the forefront of your mind when designing a notification. Will your users want to see it, hear it or interact with it?
By far, the most common type of notification used is a remote notification, in which a cloud service, usually a web server, is utilized to tell Apple’s servers that a notification should be built and sent to a device.
APNs utilizes cryptographic validation and authentication to ensure security of your messages.
Notification message flow
It is important to understand the steps between registering your app with the Apple Push Notification Service and the user actually receiving a notification.
A local notification is created and scheduled on the device, as opposed to being sent to the device from a remote provider. A local notification allows all the same features as a remote notification. The only difference is that a local notification is triggered based on a set amount of time passing, or entering/exiting a geographical area, as opposed to being pushed to the device.
While it’s easy to think of notifications as being in a type of sandbox of their own, there’s no reason to exclude other iOS-provided features to enhance your app, such as location services. You can employ location services by tying a remote notification to a user’s location. You may decide to send coupons to your customers, but only in a specific geographical area. Perhaps a guest author is reading at the local bookstore and you want to let your app’s users know about it, but only if they live close enough to make it worthwhile.
- Push notifications allow you to interact with your users outside of the normal flow of your app.
- A notification can be scheduled locally based on conditions or from a remote service and “pushed” to your device.
- Remote notifications are the most common type, and they use a Cloud service to determine that a notification should be built and sent to the device.
- Notification messages remain secure because APNs utilizes cryptographic validation and authentication.
- A local notification is created and scheduled on the device, as opposed to being sent to the device from a remote provider.
Where to go from here?
This chapter has been the first step in your journey to understanding the many facets, opportunities and challenges of leveraging push notifications.