The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojo::APNS - Apple Push Notification Service for Mojolicious

VERSION

0.02

DESCRIPTION

This module provides an API for sending messages to an iPhone using Apple Push Notification Service.

This module does not support password protected SSL keys.

SYNOPSIS

  use Mojo::APNS;

  my $apns = Mojo::APNS->new(
              key => '/path/to/apns-dev-key.pem',
              cert => '/path/to/apns-dev-cert.pem',
              sandbox => 1,
            );

  $apns->on(drain => sub { $apns->loop->stop; })
  $apns->send(
    "c9d4a07c fbbc21d6 ef87a47d 53e16983 1096a5d5 faa15b75 56f59ddd a715dff4",
    "New cool stuff!",
    badge => 2,
  );

  $apns->ioloop->start;

EVENTS

error

Emitted when an error occur between client and server. This event will also get "Timeout" events.

drain

Emitted once all messages have been sent to the server.

ATTRIBUTES

cert

Path to apple SSL certificate.

key

Path to apple SSL key.

sandbox

Booleand true for talking with "gateway.sandbox.push.apple.com". Default is to use "gateway.push.apple.com"

ioloop

Holds a Mojo::IOLoop object.

METHODS

send

  $self->send($device, $message, %args);
  $self->send($device, $message, %args, $cb);

Will send a $message to the $device. %args is optional, but can contain:

$cb will be called when the messsage has been sent or if it could not be sent. $error will be false on success.

    $cb->($self, $error);
  • badge

    The number placed on the app icon. Default is 0.

  • sound

    Default is "default".

  • Custom arguments

AUTHOR

Jan Henning Thorsen - jhthorsen@cpan.org