Skip to main content

Crate bark_apns

Crate bark_apns 

Source
Expand description

Direct APNs client for sending Bark notifications.

This crate talks to Apple Push Notification service directly with an iOS device token. It does not call a Bark server, but it keeps Bark’s payload semantics: fields such as title, body, markdown, sound, group, isArchive, id, and delete are encoded the way Bark’s notification service extension expects them.

§Examples

§Send a Simple Message

use bark_apns::{Bark, Message};

fn main() -> bark_apns::Result<()> {
    let bark = Bark::new()?;
    let message = Message::new()
        .title("Deploy")
        .body("done")
        .group("ops");

    bark.send(&message, ["device-token-from-bark-app"])?;
    Ok(())
}

§Send a Markdown Message

use bark_apns::{Bark, Message};

fn main() -> bark_apns::Result<()> {
    let bark = Bark::new()?;
    let message = Message::new()
        .title("Deploy")
        .markdown("## Deploy\n\n- status: **done**\n- target: `production`");

    bark.send(&message, ["device-token-from-bark-app"])?;
    Ok(())
}

§Send an Encrypted Message

use bark_apns::{Bark, Encryption, EncryptionAlgorithm, EncryptionMode, Message};

fn main() -> bark_apns::Result<()> {
    let bark = Bark::new()?;
    let encryption = Encryption::new(
        EncryptionAlgorithm::AES128,
        EncryptionMode::CBC,
        "1234567890123456",
    )?;

    let message = Message::new()
        .title("Deploy")
        .body("done")
        .markdown("**Deploy** finished")
        .group("ops")
        .encryption(encryption);

    bark.send(&message, ["device-token-from-bark-app"])?;
    Ok(())
}

§Notes

  • markdown follows Bark’s documented behavior: when present, Bark renders it and ignores body for display.
  • Bark parses Markdown with Apple’s Swift Markdown package and its own renderer. It supports paragraphs, headings, block quotes, bold, italic, strikethrough, inline code, code blocks, links, images, ordered and unordered lists, nested lists, task-list checkboxes, soft breaks, and hard line breaks. In notification banners, Bark uses the rendered plain-text body and collapses repeated blank lines, so styling such as bold, italic, link color, and code font is not preserved there.
  • Encrypted pushes serialize Bark request fields to JSON, encrypt that JSON, and put the result in the top-level ciphertext field. CBC and GCM pushes also include a top-level iv, matching Bark’s client-side decryptor.

Structs§

Bark
Direct APNs client for Bark notifications.
Encryption
Encryption settings for a Bark encrypted push.
Message
Builder for a Bark-compatible push message.

Enums§

EncryptionAlgorithm
AES algorithm selected in Bark’s “Push Encryption” settings.
EncryptionMode
AES block mode selected in Bark’s “Push Encryption” settings.
Error
Error type for Bark APNs operations.
InterruptionLevel
Bark interruption level for a notification.

Type Aliases§

Result
Result type used by this crate.