AnyEvent::APNS - Simple wrapper for Apple Push Notifications Service (APNS) provider


AnyEvent-APNS documentation  | view source Contained in the AnyEvent-APNS distribution.

Index


NAME

Top

AnyEvent::APNS - Simple wrapper for Apple Push Notifications Service (APNS) provider

SYNOPSIS

Top

    use AnyEvent::APNS;

    my $cv = AnyEvent->condvar;

    my $apns; $apns = AnyEvent::APNS->new(
        certificate => 'your apns certificate file',
        private_key => 'your apns private key file',
        sandbox     => 1,
        on_error    => sub { # something went wrong },
        on_connect  => sub {
            $apns->send( $device_token => {
                aps => {
                    alert => 'Message received from Bob',
                },
            });
        },
    );
    $apns->connect;

    # disconnect and exit program as soon as possible after sending a message
    # otherwise $apns makes persistent connection with apns server
    $apns->handler->on_drain(sub {
        undef $_[0];
        $cv->send;
    });

    $cv->recv;

DESCRIPTION

Top

This module helps you to create Apple Push Notifications Service (APNS) Provider.

NOTE FOR 0.01x USERS

Top

From 0.02, this module does not connect in constructor. You should call connect method explicitly to connect server.

METHODS

Top

new

Create APNS object.

    my $apns = AnyEvent::APNS->new(
        certificate => 'your apns certificate file',
        private_key => 'your apns private key file',
        sandbox     => 1,
        on_error    => sub { # something went wrong },
    );

Supported arguments are:

certificate => 'your apns certificate file'

Required

private_key => 'your apns private key file',

Required

sandbox => 0|1

This is a flag indicate target service is provisioning (sandbox => 1) or distribution (sandbox => 0)

Optional (Default: 0)

on_error => $cb->($handle, $fatal, $message)

Callback to be called when something error occurs. This is wrapper for AnyEvent::Handle's on_error callbacks. Look at the document for more detail.

Optional (Default: just warn error)

on_connect => $cb->()

Callback to be called when connection established to apns server.

Optional (Default: empty coderef)

$apns->connect;

Connect to apns server.

$apns->send( $device_token, \%payload )

Send apns messages with \%payload to device specified $device_token.

    $apns->send( $device_token => {
        aps => {
            alert => 'Message received from Bob',
        },
    });

$device_token should be a binary 32bytes device token provided by iPhone SDK (3.0 or above)

\%payload should be a hashref suitable to apple document: http://developer.apple.com/iPhone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html

Note: If you involve multi-byte strings in \%payload, it should be utf8 decoded strings not utf8 bytes.

$apns->handler

Return AnyEvent::Handle object which is used to current established connection. It returns undef before connection completed.

TODO

Top

AUTHOR

Top

Daisuke Murase <typester@cpan.org>

COPYRIGHT AND LICENSE

Top


AnyEvent-APNS documentation  | view source Contained in the AnyEvent-APNS distribution.