Home iOS & Swift Books Push Notifications by Tutorials

2
Push Notifications Written by Scott Grosch

Heads up... You're reading this book for free, with parts of this chapter shown beyond this point as scrambled text.

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 UIViewController or View can implement.

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?

Remote notifications

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.

Security

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.

Local notifications

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.

Location-aware notifications

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.

Key points

  • 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.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.

Have feedback to share about the online reading experience? If you have feedback about the UI, UX, highlighting, or other features of our online readers, you can send them to the design team with the form below:

© 2021 Razeware LLC

You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

Unlock Now

To highlight or take notes, you’ll need to own this book in a subscription or purchased by itself.