Pigeon v1.3.2 Pigeon.APNS View Source
Apple Push Notification Service (APNS)
Link to this section Summary
Types
Can be either a single notification or a list
Async callback for push notification response
Options for sending push notifications
Functions
Sends a push over APNS
Starts APNS worker connection with given config or name
Stops existing APNS worker connection
Link to this section Types
Link to this type
notification()
View Source
notification()
View Source
notification() ::
Pigeon.APNS.Notification.t() | [Pigeon.APNS.Notification.t(), ...]
notification() :: Pigeon.APNS.Notification.t() | [Pigeon.APNS.Notification.t(), ...]
Can be either a single notification or a list.
Link to this type
on_response()
View Source
on_response()
View Source
on_response() :: (Pigeon.APNS.Notification.t() -> no_return())
on_response() :: (Pigeon.APNS.Notification.t() -> no_return())
Async callback for push notification response.
Examples
handler = fn(%Pigeon.APNS.Notification{response: response}) ->
case response do
:success ->
Logger.debug "Push successful!"
:bad_device_token ->
Logger.error "Bad device token!"
_error ->
Logger.error "Some other error happened."
end
end
n = Pigeon.APNS.Notification.new("msg", "device token", "push topic")
Pigeon.APNS.push(n, on_response: handler)
Link to this type
push_opts()
View Source
push_opts()
View Source
push_opts() :: [to: atom() | pid() | nil, on_response: on_response() | nil]
push_opts() :: [to: atom() | pid() | nil, on_response: on_response() | nil]
Options for sending push notifications.
:to
- Defines worker to process push. Defaults to:apns_default
:on_response
- Optional async callback triggered on receipt of push. Seeon_response/0
Link to this section Functions
Link to this function
push(notification, opts \\ [])
View Source
push(notification, opts \\ [])
View Source
push(notification(), push_opts()) :: notification() | :ok
push(notification(), push_opts()) :: notification() | :ok
Sends a push over APNS.
Examples
iex> n = Pigeon.APNS.Notification.new("msg", "token", "topic")
iex> Pigeon.APNS.push(n)
%Pigeon.APNS.Notification{device_token: "token", expiration: nil,
response: :bad_device_token, id: nil,
payload: %{"aps" => %{"alert" => "msg"}}, topic: "topic"}
iex> n = Pigeon.APNS.Notification.new("msg", "token", "topic")
iex> Pigeon.APNS.push([n, n], on_response: nil)
:ok
iex> n = Pigeon.APNS.Notification.new("msg", "token", "topic")
iex> Pigeon.APNS.push([n, n])
[%Pigeon.APNS.Notification{device_token: "token", expiration: nil,
response: :bad_device_token, id: nil,
payload: %{"aps" => %{"alert" => "msg"}}, topic: "topic"},
%Pigeon.APNS.Notification{device_token: "token", expiration: nil,
response: :bad_device_token, id: nil,
payload: %{"aps" => %{"alert" => "msg"}}, topic: "topic"}]
Link to this function
start_connection(name)
View Source
start_connection(name)
View Source
start_connection(atom() | Pigeon.APNS.Config.t() | Keyword.t()) :: {:ok, pid()}
start_connection(atom() | Pigeon.APNS.Config.t() | Keyword.t()) :: {:ok, pid()}
Starts APNS worker connection with given config or name.
Examples
iex> config = Pigeon.APNS.Config.new(:apns_default)
iex> {:ok, pid} = Pigeon.APNS.start_connection(%{config | name: nil})
iex> Process.alive?(pid)
true
Link to this function
stop_connection(name) View Source
Stops existing APNS worker connection.
Examples
iex> config = Pigeon.APNS.Config.new(:apns_default)
iex> {:ok, pid} = Pigeon.APNS.start_connection(%{config | name: nil})
iex> Pigeon.APNS.stop_connection(pid)
:ok
iex> :timer.sleep(500)
iex> Process.alive?(pid)
false