Chapters

Hide chapters

Push Notifications by Tutorials

Fourth Edition · iOS 16 · Swift 5 · Xcode 14

Section I: Push Notifications by Tutorials

Section 1: 15 chapters
Show chapters Hide chapters

2. Push Notifications
Written by Scott Grosch

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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.
  • Most 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.
© 2024 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now