reown-com / a2

An Asynchronous Apple Push Notification (apns2) Client for Rust
MIT License
151 stars 53 forks source link

Client panicked inside hyper-alpn library #68

Closed jeromeboe closed 1 year ago

jeromeboe commented 1 year ago

I've created a project with the simplest code:

[package]
name = "push_test"
version = "0.1.0"
edition = "2021"

[dependencies]
a2 = "0.7.0"
tokio = { version = "1", features = ["full"] }
use a2::{Client, DefaultNotificationBuilder, Endpoint, NotificationBuilder, NotificationOptions};
use std::fs::File;

#[tokio::main]
async fn main() {
    let client = Client::token(
        &mut File::open("apns_authkey.p8").unwrap(),
        "my_key_id",
        "my_team_id",
        Endpoint::Sandbox,
    )
    .unwrap();

    let options = NotificationOptions {
        apns_topic: Some("com.my.app.dev"),
        ..Default::default()
    };

    let builder = DefaultNotificationBuilder::new()
        .set_title("Title")
        .set_body("Body")
        .set_sound("default");

    let payload = builder.build(
        "my_device_token",
        options,
    );

    _ = client.send(payload).await.unwrap();
}

The last line client.send() triggers the following issue when I run the build: thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /.../.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-alpn-0.4.0/src/lib.rs:263:29

All the informations provided (.p8, key_id, team_id, bundle_app_id, device_token) are working when I send a notification using external tool like PushNotifications.

Any idea how to solve this?