概述本地通知和推送通知(一)

关于本地通知和推送通知

来源:苹果链接

概述本地通知和推送通知

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.

本地通知和推送通知是一种方法,能够让程序没有在前景运行时,还可以让用户知道信息的到来。信息可以包括:短信、待办日历事件、远程更新数据。形式:弹窗、角标、声音提示。(下图)

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.

注意:本地通知和推送通知 与 广播通知(NSNotificationCenter)  或者 键-值观察通知 完全无关,不要混淆。

概述

At a Glance

Local notifications and push notifications have several important aspects you should be aware of.

本地通知和推送通知涉及到很多重要问题,这些都是需要关注的。

anchor.gif

要解决的问题

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.

前景一次只有一个应用是激活的,现在很多应用都是与时俱进的、又运行在联网状态下,所以即使应用不在前景运行,也有很多事件,特别是用户感兴趣的事件,要推送给用户。本地通知和推送通知就帮助应用实现了这项功能。

anchor.gif

Relevant Chapter: “Local and Push Notifications in Depth”

关联章节:《深入本地通知和推送通知》

anchor.gif

本地与推送通知的发生源不同

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.

两者满足了不同的设计需求。本地通知就是满足本地应用所需。推送通知,也叫远程通知,是从设备外进来的。远程通知产生于 应用提供商 的 远程服务器,然后通过苹果提供的 苹果推送通知服务(Apple Push Notification service) 被推送到本地设备。

关联章节:《深入本地通知和推送通知》

anchor.gif

本地通知是计划的,推送通知是注册的,最终在设备上统一处理

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.

要让iOS设备自己发送本地通知,应用需要创建 UILocalNotification 对象,赋值一个发送的日期和时间,指定通知的细节,然后安排它进入发送队列。要让iOS设备能够收到推送通知,应用必须注册,然后把设备令牌传给提供商。

When the operating system delivers a local notification (iOS only) or push notification (iOS or 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.

当操作系统传送本地通知或推送通知,且,目标应用没有在前景运行时,设备就会发出通知(弹窗、角标、声音),如果用户点击或划动,应用启动,同时调用方法接收本地通知对象 或 远程通知数据(payload)。如果应用正在前景运行,那么通知到来时,应用的代理方法直接获得并处理通知。

关联章节:《计划、注册、处理通知》

anchor.gif

苹果推送通知服务(APNs)是推送通知的入口

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.

APNs散布推送通知到应用已经注册的设备上。每台设备创建了标准的、认可的、加密的 IP连接,连接到 APNs,然后接收通知。应用的提供者(APP开发商)与 APNs保持安全、持续连接,监控进入数据,当有新数据时,开发商就通过 APNs 向目标设备发送。

anchor.gif

Related Chapter: “Apple Push Notification Service”

关联章节:《APNs》

anchor.gif

你必须获取安全认证才能使用推送通知

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, one for development and one for 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.

如果开发者要采用远程推送通知,你必须从苹果开发中心(Dev Center)获取 SSL 认证。每个认证限于一个应用,认证由 bundle ID确认。认证限于两个环境,一个为开发环境,一个为正式产品环境。两个环境有各自独立的IP地址对应,每个IP需要独立认证,每个环境又都需要 provisioning profiles 信息。

关联章节:《提供认证和开发》

anchor.gif

应用开发者使用二进制接口(Binary Interface)与APNs通讯

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

二进制接口是异步的,使用TCP套接字流(streaming TCP socket)设计,应用开发者发送二进制内容的推送通知到 APNs。应用于开发环境和产品发布环境的接口是独立的,地址和接口各不相同。每个接口都需要使用 TLS(或SSL),以便建立安全通讯通道。开发者通过该安全通道,压缩通知数据并发送到 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.

APNs具有应答服务(feedback service),该服务为每个应用维持一个列表,记录发送失败情况。开发者应该定期检查失败的,实施再次发送。

关联章节:《苹果推送通知服务》、《开发者与苹果推送服务如何通讯》

anchor.gif

先修内容

Prerequisites

iOS App Programming Guide describes the high level patterns for writing iOS apps.

《iOS应用编程指南》讲述了编写App的高级模式。

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.

要了解iOS开发,还需要TLS/SSL知识,以及套接字流的知识。

anchor.gif

参考

See Also

The following documents provide background information:

  • iOS Team Administration Guide describes how to perform a variety of tasks in the iOS Portal, such as provisioning devices for development.

    《iOS团队管理指南》描述了在iOS Portal中如何执行不同任务,如开发中如何认证设备。

  • Entitlement Key Reference documents the specific entitlements needed for an app to receive push notifications.

    《认证键参考》列出了app获取推送通知所需的认证条件。

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

其他传统文档:

  • The reference documentation for UILocalNotificationUIApplication, 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 OS X.

  • Security Overview describes the security technologies and techniques used for the iOS and Macs.

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

For information on how to send push notifications to your website visitors using OS X, read “Configuring Safari Push Notifications” in Notification Programming Guide for Websites.

转载于:https://my.oschina.net/zhmsong/blog/172890

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值