apns_connection (apns v2.6.0)

This gen_statem handles the APNs Connection.

Copyright 2017 Erlang Solutions Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Summary

Types

Link to this type

connection/0

-type connection() ::
          #{name := name(),
            apple_host := host(),
            apple_port := inet:port_number(),
            certdata => binary(),
            certfile => path(),
            keydata => keydata(),
            keyfile => path(),
            timeout => integer(),
            type := type(),
            proxy_info => proxy_info()}.
-type host() :: string() | inet:ip_address().
-type keydata() :: {'RSAPrivateKey' | 'DSAPrivateKey' | 'ECPrivateKey' | 'PrivateKeyInfo', binary()}.
-type name() :: atom().
Link to this type

notification/0

-type notification() :: binary().
-type path() :: string().
Link to this type

proxy_info/0

-type proxy_info() ::
          #{type := connect,
            host := host(),
            port := inet:port_number(),
            username => iodata(),
            password => iodata()}.
-opaque state()
-type type() :: certdata | cert | token.

Functions

Link to this function

await_tunnel_up(EventType, EventContent, StateData)

-spec await_tunnel_up(_, _, _) -> _.
Link to this function

await_up(EventType, EventContent, StateData)

-spec await_up(_, _, _) -> _.
Link to this function

callback_mode()

-spec callback_mode() -> state_functions.
-spec certdata(connection()) -> binary().
-spec certfile(connection()) -> path().
Link to this function

close_connection(ConnectionId)

-spec close_connection(name() | pid()) -> ok.

Close the connection with APNs gracefully

Link to this function

code_change(OldVsn, StateName, StateData, Extra)

-spec code_change(OldVsn :: term() | {down, term()}, StateName, StateData, Extra :: term()) ->
                     {ok, StateName, StateData}.
Link to this function

connected(EventType, Event, StateData)

-spec connected(_, _, _) -> _.
Link to this function

default_connection(_, ConnectionName)

-spec default_connection(type(), name()) -> connection().

Builds a connection() map from the environment variables.

Link to this function

down(EventType, EventContent, StateData)

-spec down(_, _, _) -> _.
Link to this function

gun_pid(ConnectionId)

-spec gun_pid(name() | pid()) -> pid().

Returns the gun's connection PID. This function is only used in tests.

-spec host(connection()) -> host().
-spec init({connection(), pid()}) ->
              {ok, open_connection, State :: state(), {next_event, internal, init}}.
-spec keydata(connection()) -> keydata().
-spec keyfile(connection()) -> path().
-spec name(connection()) -> name().
Link to this function

open_common(_, _, StateData)

-spec open_common(_, _, _) -> _.
Link to this function

open_connection(_, _, StateData)

-spec open_connection(_, _, _) -> _.
Link to this function

open_origin(_, _, StateData)

-spec open_origin(_, _, _) -> _.
Link to this function

open_proxy(_, _, StateData)

-spec open_proxy(_, _, _) -> _.
-spec port(connection()) -> inet:port_number().
Link to this function

proxy_connect_to_origin(_, _, StateData)

-spec proxy_connect_to_origin(_, _, _) -> _.
Link to this function

push_notification(ConnectionId, DeviceId, Notification, Headers)

-spec push_notification(name() | pid(), apns:device_id(), notification(), apns:headers()) ->
                           apns:response() | {error, not_connection_owner}.

Pushes notification to certificate APNs connection.

Link to this function

push_notification(ConnectionId, Token, DeviceId, Notification, Headers)

-spec push_notification(name() | pid(), apns:token(), apns:device_id(), notification(), apns:headers()) ->
                           apns:response() | {error, not_connection_owner}.

Pushes notification to certificate APNs connection.

Link to this function

reply_errors_and_cancel_timers(Streams, Reason)

-spec reply_errors_and_cancel_timers(map(), term()) -> ok.
Link to this function

start_link(Connection, Client)

-spec start_link(connection(), pid()) -> {ok, Pid :: pid()} | ignore | {error, Reason :: term()}.

starts the gen_statem

-spec type(connection()) -> type().
Link to this function

wait_apns_connection_up(Server)

-spec wait_apns_connection_up(pid()) -> ok.

Waits until the APNS connection is up.

Note that this function does not need to be called before sending push notifications, since they will be queued up and sent when the connection is established.