pub struct Bark { /* private fields */ }Expand description
Direct APNs client for Bark notifications.
Bark signs APNs provider tokens with Bark’s default credentials by default
and sends serialized Message payloads to iOS device tokens. It talks to
APNs directly; no Bark server is contacted.
Device tokens are normalized before sending: surrounding angle brackets and ASCII whitespace are removed, and duplicate tokens are sent once.
Implementations§
Source§impl Bark
impl Bark
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a client using Bark’s default APNs team id, key id, topic, and private key.
This matches the public Bark app topic me.fin.bark.
§Errors
Returns an error if the built-in APNs key cannot be parsed or the HTTP clients cannot be constructed.
Sourcepub fn with_credentials<T, K, O, P>(
team_id: T,
auth_key_id: K,
topic: O,
private_key_pem: P,
) -> Result<Self>
pub fn with_credentials<T, K, O, P>( team_id: T, auth_key_id: K, topic: O, private_key_pem: P, ) -> Result<Self>
Creates a client with custom APNs credentials.
Use this for a forked Bark app or a private APNs topic. The private key must be an APNs Auth Key in PEM format for ES256 signing.
§Errors
Returns an error if the private key cannot be parsed or the HTTP clients cannot be constructed.
Sourcepub fn production(self) -> Self
pub fn production(self) -> Self
Selects APNs production.
This is the default and sends to api.push.apple.com.
Sourcepub fn sandbox(self) -> Self
pub fn sandbox(self) -> Self
Selects APNs sandbox.
This sends to api.sandbox.push.apple.com, useful for development builds
whose device tokens belong to the sandbox environment.
Sourcepub fn auth_key_id(&self) -> &str
pub fn auth_key_id(&self) -> &str
Returns the APNs auth key id used in the JWT header.
Sourcepub fn send<I, D>(&self, message: &Message, devices: I) -> Result<()>
pub fn send<I, D>(&self, message: &Message, devices: I) -> Result<()>
Sends a message synchronously to one or more device tokens.
The same serialized APNs payload is sent to each unique normalized token.
For delete messages this method uses APNs background push type and
priority 5; otherwise it uses alert push type and priority 10.
§Errors
Returns Error::ApnsFailures if any device fails. The error message
includes the normalized device token and reason for each failed device.
Validation, serialization, encryption, token-signing, and HTTP client
errors are returned directly.
Sourcepub async fn send_async<I, D>(
&self,
message: &Message,
devices: I,
) -> Result<()>
pub async fn send_async<I, D>( &self, message: &Message, devices: I, ) -> Result<()>
Sends a message asynchronously to one or more device tokens.
This has the same payload and error semantics as Bark::send, but uses
the asynchronous reqwest client.
§Errors
Returns Error::ApnsFailures if any device fails. The error message
includes the normalized device token and reason for each failed device.
Validation, serialization, encryption, token-signing, and HTTP client
errors are returned directly.