Skip to content

Latest commit

 

History

History
211 lines (134 loc) · 6.07 KB

sc_push_svc_apns.md

File metadata and controls

211 lines (134 loc) · 6.07 KB

Module sc_push_svc_apns

Apple Push Notification Service (APNS) API.

Copyright (c) 2015 Silent Circle

Behaviours: supervisor.

Authors: Edwin Fine (efine@silentcircle.com).

Description

This is the API to the Apple Push Notification Service Provider.

   Opts = [
               {host, "gateway.sandbox.push.apple.com"},
               {port, 2195},
               {bundle_seed_id, <<"com.example.Push">>},
               {bundle_id, <<"com.example.Push">>},
               {ssl_opts, [
                   {certfile, "/somewhere/cert.pem"},
                   {keyfile, "/somewhere/key.unencrypted.pem"}
                   ]
               }
           ],
   {ok, Pid} = sc_push_svc_apns:start_session(my_push_tester, Opts).
   Notification = [{alert, Alert}, {token, <<"e7b300...a67b">>}],
   {ok, SeqNo} = sc_push_svc_apns:send(my_push_tester, Notification).
   JSON = get_json_payload(), % See APNS docs for format
   {ok, SeqNo} = apns_erl_session:send(my_push_tester, Token, JSON).
   ok = sc_push_svc_apns:stop_session(my_push_tester).

Data Types


gen_proplist() = sc_types:proplist(atom(), term())

Function Index

async_send/2Asynchronously sends a notification specified by proplist Notification to SvrRef; Same as send/2 beside returning only 'ok' for success.
async_send/3Asynchronously sends a notification specified by proplist Notification to SvrRef; Same as send/3 beside returning only 'ok' for success.
init/1
send/2Send a notification specified by proplist Notification to SvrRef.
send/3Send a notification specified by proplist Notification via SvrRef using options Opts.
start_link/1Opts is a list of proplists.
start_session/2Start named session for specific host and certificate as supplied in the proplist Opts.
stop_session/1Stop named session.

Function Details

async_send/2


async_send(Name::term(), Notification::gen_proplist()) -> ok | {error, Reason::term()}

Asynchronously sends a notification specified by proplist Notification to SvrRef; Same as send/2 beside returning only 'ok' for success.

async_send/3


async_send(Name::term(), Notification::gen_proplist(), Opts::gen_proplist()) -> ok | {error, Reason::term()}

Asynchronously sends a notification specified by proplist Notification to SvrRef; Same as send/3 beside returning only 'ok' for success.

init/1

init(Opts) -> any()

send/2


send(Name::term(), Notification::gen_proplist()) -> {ok, Ref::term()} | {error, Reason::term()}

Send a notification specified by proplist Notification to SvrRef.

Set the notification to expire in a very very long time.

Send an alert with a sound and extra data

  Name = 'com.example.AppId',
  Notification = [
     {alert, <<"Hello">>},
     {token, <<"ea3f...">>},
     {aps, [
       {sound, <<"bang">>},
       {extra, [{a, 1}]}]}
  ],
  sc_push_svc_apns:send(Name, Notification).

See also: send/3.

send/3


send(Name::term(), Notification::gen_proplist(), Opts::gen_proplist()) -> {ok, Ref::term()} | {error, Reason::term()}

Send a notification specified by proplist Notification via SvrRef using options Opts. Note that Opts currently has no supported actions.

start_link/1


start_link(Opts::list()) -> {ok, pid()} | {error, term()}

Opts is a list of proplists. Each proplist is a session definition containing name, mod, and config keys.

start_session/2


start_session(Name::atom(), Opts::list()) -> {ok, pid()} | {error, already_started} | {error, Reason::term()}

Start named session for specific host and certificate as supplied in the proplist Opts.

See also: apns_erl_session_sup:start_child/2.

stop_session/1


stop_session(Name::atom()) -> ok | {error, Reason::term()}

Stop named session.