iOS远程推送

来源:互联网 发布:淘宝iphone7有假货吗 编辑:程序博客网 时间:2024/05/23 22:57

iOS远程推送

远程推送通知本地通知 都属于 用户通知(User notificaiton1)。

User notifications enable an app that isn’t running in the foreground to let its users know it has information for them.

APNs

APNs2是iOS系统下应用程序实现远程推送的核心。iOS平台不允许应用长期地后台运行并连接网络,因此应用不在前台运行时,应用消息不能及时地从服务器(Provider)直接传达到客户端(Client)。APNs的出现就是作为一个中转站。

iOS远程推送的过程如下

A remote notification from a provider to a client application

APNs transports and routes remote notifications for your apps from your provider to each user’s device.

从应用注册远程推送到接受远程推送的流程如下

Device Token

设备令牌,这个概念一直贯穿了整个推送的过程。

deviceToken is A token that identifies the device to APNs.
Device Token:
A device token is an identifier for the Apple Push Notification System for iOS devices. Apple assigns a Device Token on a per-app basis (iOS 7 and later) which is used as a unique identifier for sending push notifications. Each device has two device tokens per app: one for development, and one for production (ad hoc or app store builds). The tokens are 64 hexadecimal characters.
Note that the device token is different from the uniqueIdentifier property of UIDevice because, for security and privacy reasons, it must change when the device is wiped.
The device token you provide to the server is analogous to a phone number; it contains information that enables APNs to locate the device on which your client app is installed. APNs also uses it to authenticate the routing of a notification. The device token is provided to you by your client app, which receives the token after registering itself with the remote notification service.

Each provider must have a unique provider certificate and private cryptographic key, which are used to validate the provider’s connection with APNs. The provider certificate (which is provisioned by Apple) identifies the topics supported by the provider. (A topic is the bundle ID associated with one of your apps.)

与APNs连接的服务器必须有SSL证书,该证书有应用程序的bundle ID3。

News

New Provider API feature

  • HTTP/24 requese-response
  • Instant feedback
  • Simpled certificate(Universal Push Notification Client SSL Certificate) handling
  • 4KB payload



注:
1. 需要付费的Apple开发者账号
2. 仅支持真机测试,iOS模拟器无法处理远程通知
3. 需要为Provider向Apple申请SSL证书
4. Web服务器(运行在Mac上的就足够了)


  1. 区别于广播通知 broadcast notifications (managed by the NSNotificationCenter class ) 和 键值观察通知 key-value observing notification ↩
  2. Apple Push Notification service ↩
  3. com.yourcompany.yourapp ↩
  4. HTTP/2 是 HTTP 协议发布后的首个更新,于 2015 年 2 月 17 日被批准。它采用了一系列优化技术来整体提升 HTTP 协议的传输性能,如异步连接复用、头压缩等等,可谓是当前互联网应用开发中,网络层次架构优化的首选方案之一。 ↩
原创粉丝点击