View Source Pigeon.APNS (Pigeon v1.6.3)

Apple Push Notification Service (APNS)

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.

Types

@type notification() ::
  Pigeon.APNS.Notification.t() | [Pigeon.APNS.Notification.t(), ...]

Can be either a single notification or a list.

@type 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)
@type 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. See on_response/0

Functions

Link to this function

push(notification, opts \\ [])

View Source
@spec 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"}]
@spec 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
@spec stop_connection(atom() | pid()) :: :ok

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