Skip to content

pelov/p5-Net-APNS-Simple

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Net::APNS::Simple - APNS Perl implementation

DESCRIPTION

A Perl implementation for sending notifications via APNS using Apple's new HTTP/2 API. This library uses Protocol::HTTP2::Client as http2 backend. And it also supports multiple stream at one connection. (It does not correspond to parallel stream because APNS server returns SETTINGS_MAX_CONCURRENT_STREAMS = 1.)

SYNOPSIS

use Net::APNS::Simple;

# With provider authentication tokens
my $apns = Net::APNS::Simple->new(
    # enable if development
    # development => 1,
    auth_key => '/path/to/auth_key.p8',
    key_id => 'AUTH_KEY_ID',
    team_id => 'APP_PREFIX',
    bundle_id => 'APP_ID',
);

# With SSL certificates
my $apns = Net::APNS::Simple->new(
    # enable if development
    # development => 1,
    cert_file => '/path/to/cert.pem',
    key_file => '/path/to/key.pem',
    passwd_cb => sub { return 'key-password' },
    bundle_id => 'APP_ID',
);

# 1st request
$apns->prepare('DEVICE_ID',{
        aps => {
            alert => 'APNS message: HELLO!',
            badge => 1,
            sound => "default",
            # SEE: https://developer.apple.com/jp/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html,
        },
    }, sub {
        my ($header, $content) = @_;
        require Data::Dumper;
        print Dumper $header;

        # $VAR1 = [
        #           ':status',
        #           '200',
        #           'apns-id',
        #           '791DE8BA-7CAA-B820-BD2D-5B12653A8DF3'
        #         ];

        print Dumper $content;

        # $VAR1 = undef;
    }
);

# 2nd request
$apns->prepare(...);

# also supports method chain
# $apns->prepare(1st request)->prepare(2nd request)....

# send notification
$apns->notify();

METHODS

my $apns = Net::APNS::Simple->new(%arg)

  • development : bool

    Switch API's URL to 'api.sandbox.push.apple.com' if enabled.

  • auth_key : string

    Private key file for APNS obtained from Apple.

  • team_id : string

    Team ID (App Prefix)

  • bundle_id : string

    Bundle ID (App ID)

  • cert_file : string

    SSL certificate file.

  • key_file : string

    SSL key file.

  • passwd_cb : sub reference

    If the private key is encrypted, this should be a reference to a subroutine that should return the password required to decrypt your private key.

  • apns_id : string

    Canonical UUID that identifies the notification (apns-id header).

  • apns_expiration : number

    Sets the apns-expiration header.

  • apns_priority : number

    Sets the apns-priority header. Default 10.

  • apns_collapse_id : string

    Sets the apns-collapse-id header.

  • apns_push_type : string

    Sets the apns-push-type header.

  • proxy : string

    URL of a proxy server. Default $ENV{https_proxy}. Pass undef to disable proxy.

    All properties can be accessed as Getter/Setter like $apns->development.

$apns->prepare($DEVICE_ID, $PAYLOAD);

Prepare notification. It is possible to specify more than one. Please do before invoking notify method.

$apns->prepare(1st request)->prepare(2nd request)....

Payload please refer: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple\_ref/doc/uid/TP40008194-CH17-SW1.

$apns->notify();

Execute notification. Multiple notifications can be executed with one SSL connection.

LICENSE

Copyright (C) Tooru Tsurukawa.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Tooru Tsurukawa <rockbone.g at gmail.com>

About

APNS Perl implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Perl 97.9%
  • Lua 2.1%