天天看点

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Push Notification on iOS

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Brief Flow

  • Send Notification request to APNs
  • APNs delivers the notification to target Devices(APPs)
  • APNs will retry later if device power off.

Pushing remote notifications from multiple providers to multiple devices

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Establishing certificate-based provider connection trust

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Establishing and using token-based provider connection trust

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Establishing connection trust between a device and APNs

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Managing the device token

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Remote notification path from provider to device

[iOS]Push Notification on iOS(1)Push Notification on iOSEstablishing and using token-based provider connection trustReference

Provider Server

  • Device tokens from APNs
  • Build and sent notification request to APNs
  • JSON
  • Schedule Task
  • Certificate
    • Communicate with APNs using authentication tokens

    For security, APNs requires you to refresh your token regularly. Refresh your token no more than once every 20 minutes and no less than once every 60 minutes. APNs rejects any request whose token contains a timestamp that is more than one hour old. Similarly, APNs reports an error if you recreate your tokens more than once every 20 minutes.

    On your provider server, set up a recurring task to recreate your token with a current timestamp. Encrypt the token again and attach it to subsequent notification requests.

    • Communicate with APNs using a TLS certificate
    Provider certificates are valid for a year and must be updated to continue communicating with APNs.
  • Implementation
    • Python (PyAPNs)
    • NodeJS (node-apn)
  • Setting Up a Remote Notification Server

APNs (Apple Push Notification service)

  • JSON Web Token (JWT) & Certificate
    • Establishing a Token-Based Connection to APNs
    • Establishing a Certificate-Based Connection to APNs
  • Encrypt/Decrypt Device Token
  • Deliver Push Notification

Client App (Remote Notification)

  • Enable Push Notification (Xcode & Apple Account)
  • Register with Apple Push Notification service (APNs) and receive an app-specific device token.
  • Send the device token to your notification provider server.
  • Device Token
APNs can issue a new device token for a variety of reasons:

User installs your app on a new device

User restores device from a backup

User reinstalls the operating system

Other system-defined events

As a result, apps must request the device token at launch time

To protect user privacy, do not use device tokens to identify user devices.

  • Implement support for handling incoming remote notifications
  • Configuring Remote Notification Support
NOTE
The ability of APNs to deliver remote notifications to a nonrunning app requires the app to have been launched at least once.
On an iOS device, if a user force-quits your app using the app multitasking UI, the app does not receive remote notifications until the user relaunches it.
  • UserNotifications

Reference

  • APNs Overview
  • Local and Remote Notification Programming Guide
  • https://onevcat.com/2016/08/notification/
  • FCM (Firebase Cloud Messaging)