Notification in iPhone

Introduction

         
The notification mechanism of Cocoa implements a one-to-many broadcast of messages based on the Observer pattern. Objects in a program add themselves or other objects to a list of observers of one or more notifications, each of which is identified by a global string (the notification name). The object that wants to notify other objects, the observed object, creates a notification object and posts it to a notification center. The notification center determines the observers of a particular notification and sends the notification to them via a message. The methods invoked by the notification message must conform to a certain single-parameter signature. The parameter of the method is the notification object, that contains the notification name, the observed object, and a dictionary containing any supplemental information.Posting a notification is a synchronous procedure. The posting object doesn't regain control until the notification center has broadcast the notification to all observers. For asynchronous behavior, you can put the notification in a notification queue; control returns immediately to the posting object and the notification center broadcasts the notification when it reaches the top of the queue.Regular notifications; that is, those broadcast by the notification center, are intraprocess only. If you want to broadcast notifications to other processes then you can use the distributed notification center and its related API.

Push Notification

   This service is provided by Apple in which, rather than pinging a server after a specific interval for data that is also called a pull mechanism, the server will send a notification to your device that there is a new piece of information for you. The request is initiated by the server not the device or client.

For example, maybe the user received a new tweet. Perhaps their favorite team has won a game, or their dinner is ready. Since the app isn't currently running, it cannot check for these events.

Luckily, Apple has provided a solution to this. Instead of your app continuously checking for events or doing work in the background, you can write a server-side component to do this instead.
And when an event of interest occurs, the server-side component can send the app a push notification! There are three things a push notification can do:

  • Display a short text message
  • Play a brief sound
  • Set a number in a badge on the app's icon

Flow of push notification

   Your web server sends a message (device token + payload) to the Apple Push Notification Service (APNS) , then APNS routes this message to the device whose device token is specified in the notification.

To better understand it I will use one more example.

Imagine, you are looking for a job. You go to a software company daily and ask sir "is there a job for me" and they keep on saying no.  Your time and money is wasted on each trip. (Pull Request mechanism)

So, one day the owner says, if there is any suitable job for you, I will let you know. In this mechanism, your time and money is not wasted. (Push Mechanism).


Similar Articles