1Local Notifications and Push NotificationsIntroduction

About Local Notifications and Push Notifications

Local notifications and push notifications are ways for an application that isn’t running in the foreground(前景) to let its users know it has information for them. The information could be a message, an impending(即将到来的) calendar(日历) event, or new data on a remote server. When presented(提交) by the operating system, local and push notifications look and sound the same. They can display an alert message or they can badge(微章) the application icon. They can also play a sound when the alert or badge number is shown.

Push notifications were introduced in iOS 3.0 and in Mac OS X version 10.7. Local notifications were introduced in iOS 4.0; they are not available in Mac OS X.

 

When users are notified(通知) that the application has a message, event, or other data for them, they can launch the application and see the details. They can also choose to ignore(忽略) the notification, in which case the application is not activated.

Note: Push notifications and local notifications are not related to(不涉及) broadcast(广播) notifications (NSNotificationCenter) or key-value observing notifications.

 

At a Glance(瞥,一览)

Local notifications and push notifications have several important aspects(方面) you should be aware of(知道).

The Problem That Local and Push Notifications Solve

Only one application can be active in the foreground at any time. Many applications operate in a time-based or interconnected(互联) environment where events of interest to users can occur when the application is not in the foreground. Local and push notifications allow these applications to notify their users when these events occur.

Relevant(相关的) Chapter: “Local and Push Notifications in Depth”

 

Local and Push Notifications Are Different in Origination(起源)

Local and push notifications serve different design needs. A local notification is local to an application on an iPhone, iPad, or iPod touch. Push notifications—also known as remote notifications—arrive from outside a device. They originate on a remote server—the application’s provider—and are pushed to applications on devices (via the Apple Push Notification service) when there are messages to see or data to download.

Relevant Chapter: “Local and Push Notifications in Depth”

 

You Schedule a Local Notification, Register a Push Notification, and Handle Both

To have iOS deliver a local notification at a later time, an application creates a UILocalNotification object, assigns it a delivery date and time, specifies presentation(说明) details, and schedules it. To receive push notifications, an application must register to receive the notifications and then pass to its provider a device token it gets from the operating system.

When the operating system delivers a local notification (iOS only) or push notification (iOS or Mac OS X) and the target application is not running in the foreground, it presents the notification (alert, icon badge number, sound). If there is a notification alert and the user taps or clicks the action button (or moves the action slider), the application launches and calls a method to pass in the local-notification object or remote-notification payload. If the application is running in the foreground when the notification is delivered, the application delegate receives a local or push notification.

Relevant Chapter: “Scheduling, Registering, and Handling Notifications”

 

The Apple Push Notification Service Is the Gateway(网关、出入口) for Push Notifications

Apple Push Notification service (APNs) propagates(传播) push notifications to devices having applications registered to receive those notifications. Each device establishes(建立) an accredited(认可) and encrypted IP connection with the service and receives notifications over this persistent(持久的) connection. Providers connect with APNs through a persistent and secure channel while monitoring incoming data intended for their client applications. When new data for an application arrives, the provider prepares and sends a notification through the channel to APNs, which pushes the notification to the target device.

Related Chapter: “Apple Push Notification Service”

 

You Must Obtain Security Credentials(证书) for Push Notifications

To develop and deploy the provider side of an application for push notifications, you must get SSL certificates from the appropriate Dev Center. Each certificate is limited to a single application, identified by its bundle ID; it is also limited to one of two environments, sandbox (for development and testing) and production. These environments have their own assigned IP address and require their own certificates. You must also obtain provisioning profiles for each of these environments.

Related Chapter: “Provisioning and Development”

 

The Provider Communicates with APNs over a Binary Interface(二进制接口)

The binary interface is asynchronous and uses a streaming TCP socket design for sending push notifications as binary content to APNs. There is a separate interface for the sandbox and production environments, each with its own address and port. For each interface, you need to use TLS (or SSL) and the SSL certificate you obtained to establish a secured communications channel. The provider composes(组成) each outgoing notification and sends it over this channel to APNs.

APNs has a feedback service that maintains a per-application list of devices for which there were failed-delivery attempts (that is, APNs was unable to deliver a push notification to an application on a device). Periodically(定期), the provider should connect with the feedback service to see what devices have persistent failures so that it can refrain(避免) from sending push notifications to them.

Related Chapters: “Apple Push Notification Service,” “Provider Communication with Apple Push Notification Service”

 

Prerequisites(先觉条件)

For local notifications and the client-side implementation of push notifications, familiarity(熟悉) with application development for iOS is assumed(假定). For the provider side of the implementation, knowledge of TLS/SSL and streaming sockets is helpful.

See Also

You might find these additional sources of information useful for understanding and implementing local and push notifications :

  • The reference documentation(文档) for UILocalNotification, UIApplication, and UIApplicationDelegate describe the local- and push-notification API for client applications in iOS.
  • The reference documentation for NSApplication and NSApplicationDelegate Protocol describe the push-notification API for client applications in Mac OS X.
  • Security Overview describes the security technologies and techniques(技术) used for the iOS and Mac OS X platforms.
  • RFC 5246 is the standard for the TLS protocol. Secure communication between data providers and Apple Push Notification Service requires knowledge of Transport Layer Security (TLS) or its predecessor(前任), Secure Sockets Layer (SSL). Refer to(请参阅) one of the many online or printed descriptions of these cryptographic(加密) protocols for further information.
原文地址:https://www.cnblogs.com/xingchen/p/2434093.html