33 releases

0.10.0 May 5, 2024
0.8.1 Apr 25, 2024
0.8.0 Aug 29, 2023
0.7.1 Jun 5, 2023
0.3.3 Jun 26, 2018

#390 in Network programming

Download history 329/week @ 2024-07-21 420/week @ 2024-07-28 216/week @ 2024-08-04 284/week @ 2024-08-11 197/week @ 2024-08-18 438/week @ 2024-08-25 250/week @ 2024-09-01 244/week @ 2024-09-08 187/week @ 2024-09-15 359/week @ 2024-09-22 225/week @ 2024-09-29 228/week @ 2024-10-06 214/week @ 2024-10-13 277/week @ 2024-10-20 307/week @ 2024-10-27 187/week @ 2024-11-03

997 downloads per month
Used in xorc-notifications

MIT license

100KB
1.5K SLoC

a2

CI Status MIT licensed crates.io docs.rs

HTTP/2 Apple Push Notification Service for Rust using Tokio and async sending.

Requirements

Needs a Tokio executor version 1.0 or later and Rust compiler version 1.60.0 or later.

Features

  • Fast asynchronous sending, based on h2 and hyper crates.
  • Payload serialization/deserialization with serde.
  • Provides a type-safe way of constructing different types of payloads. Custom data through Serialize, allowing use of structs or dynamic hashmaps.
  • Supports .p12 certificate databases to connect using a custom certificate.
  • Supports .p8 private keys to connect using authentication tokens.
  • If using authentication tokens, handles signature renewing for Apple's guidelines and caching for maximum performance.
  • Cryptography primitives are provided either by openssl or ring.

Examples

The library supports connecting to Apple Push Notification service either using a certificate with a password or a private key with a team id and key id. Both are available from your Apple account and with both it is possible to send push notifications to one application.

To see it used in a real project, take a look to the Echo Server, which is a project by WalletConnect to handle incoming webhooks and converting them to push notifications.

Gotchas

We've been pushing some millions of notifications daily through this library and are quite happy with it. Some things to know, if you're evaluating the library for production use:

  • Do not open new connections for every request. Apple will treat it as Denial of Service attack and block the sending IP address. When using the same Client for multiple requests, the Client keeps the connection alive if pushing steady traffic through it.

  • For one app, one connection is quite enough already for certain kind of loads. With http2 protocol, the events are asynchronous and the pipeline can hold several outgoing requests at the same time. The biggest reason to open several connections is for redundancy, running your sender service on different machines.

  • It seems to be Apple doesn't like when sending tons of notifications with faulty device tokens and it might lead to ConnectionErrors. Do not send more notifications with tokens that return Unregistered, BadDeviceToken or DeviceTokenNotForTopic.

Tests

cargo test

Dependencies

~17–28MB
~508K SLoC