O'Reilly logo

iOS 8 Swift Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 16. Notifications

16.0. Introduction

Notifications are objects that can carry data and be broadcast to multiple receivers. They are very good for decomposing work into different pieces of code, but can easily get out of hand if you misuse them. You should understand the limitations of notifications. We will talk more about their uses in this chapter and learn when you are better off without them.

Three types of notifications are available in iOS:

A normal notification (an instance of NSNotification class)

This is a simple notification that your app can broadcast to all possible receivers inside your app. iOS also broadcasts notifications of this type to your app while your app is in the foreground, informing you of various system events that are happening, such as the keyboard showing or being hidden. These notifications are great for decoupling code, in that they can allow you to cleanly separate various components in a complex iOS application.

A local notification (an instance of UILocalNotification class)

This is a notification that you schedule to be delivered to your app at a specific time. Your app can receive it even if the app is in the background or not running at all, and the app is started if the notification is delivered while your app is not running. You would normally schedule a local notification if you want to ensure that your app gets woken up (granted that the user permits this action, as we will see later) at a specific time of the day.

Push notifications

This ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required