| Crates.io | apnoxide |
| lib.rs | apnoxide |
| version | 0.1.1 |
| created_at | 2025-04-20 12:45:05.469485+00 |
| updated_at | 2025-04-20 23:43:55.906474+00 |
| description | Apple Push Notification Service for Rust built on `reqwest` |
| homepage | |
| repository | https://github.com/NanamiNakano/apnoxide |
| max_upload_size | |
| id | 1641678 |
| size | 74,370 |
Apple Push Notification Service for Rust built on reqwest
fn main() {
// currently supports PKCS #8 only
let key = fs::read_to_string("/path/to/private_key.p8").unwrap();
// initialize apn client
let cfg =
APNClientConfig::new("TEAM_ID", "KEY_ID", &key, Endpoint::production()).unwrap();
let mut client = APNClient::new(cfg).unwrap();
// build payload
let payload = Payload {
aps: Notification {
alert: Some(Alert::Full {
title: Some(Title::Normal("Title".to_string())),
subtitle: Some(Subtitle::Localized {
key: "SUBTITLE_KEY".to_string(),
args: None,
}),
body: None,
launch_image: None,
}),
sound: Some(Sound::Critical {
critical: Some(true),
name: None,
volume: None,
}),
mutable_content: Some(true),
interruption_level: Some(InterruptionLevel::TimeSensitive),
..Notification::default()
},
custom: None,
};
// build options
let option = PushOption {
topic: "com.example.topic",
..PushOption::default()
};
// push notification
let res = client
.push(
&payload,
"device_token",
option,
)
.await;
// handle error
match res {
Ok(_) => {}
Err(err) => {
match err {
APNError => {
println!("{:?}", err.error)
}
_ => {}
}
}
}
}