Pigeon.APNS.Notification (Pigeon v2.0.0-rc.0) View Source

Defines APNS notification struct and constructor functions.

Link to this section Summary

Types

APNS push response

t()

APNS notification

Functions

Returns an APNS.Notification struct with given message, device token, and topic (optional).

Returns an APNS.Notification struct with given message, device token, topic, and message ID.

Updates "alert" key in push payload.

Updates "badge" key in push payload.

Updates "category" key in push payload.

Sets "content-available" flag in push payload.

Puts custom data in push payload.

Sets "mutable-content" flag in push payload.

Updates "sound" key in push payload.

Updates "target-content-id" key in push payload.

Updates "thread-id" key in push payload.

Link to this section Types

Specs

error_response() ::
  :bad_collapse_id
  | :bad_device_token
  | :bad_expiration_date
  | :bad_message_id
  | :bad_priority
  | :bad_topic
  | :device_token_not_for_topic
  | :duplicate_headers
  | :idle_timeout
  | :invalid_push_type
  | :missing_device_token
  | :missing_topic
  | :payload_empty
  | :topic_disallowed
  | :bad_certificate
  | :bad_certificate_environment
  | :expired_provider_token
  | :forbidden
  | :invalid_provider_token
  | :missing_provider_token
  | :bad_path
  | :method_not_allowed
  | :unregistered
  | :payload_too_large
  | :too_many_provider_token_updates
  | :too_many_requests
  | :internal_server_error
  | :service_unavailable
  | :shutdown
  | :unknown_error

Specs

response() :: nil | :success | error_response() | :timeout

APNS push response

  • nil - Push has not been sent yet.
  • :success - Push was successfully sent.
  • t:Pigeon.APNS.Error.error_response/0 - Push attempted but server responded with error.
  • :timeout - Internal error. Push did not reach APNS servers.

Specs

t() :: %Pigeon.APNS.Notification{
  __meta__: Pigeon.Metadata.t(),
  collapse_id: String.t() | nil,
  device_token: String.t() | nil,
  expiration: non_neg_integer() | nil,
  id: String.t() | nil,
  payload: %{required(String.t()) => term()},
  priority: non_neg_integer() | nil,
  push_type: String.t() | nil,
  response: response(),
  topic: String.t() | nil
}

APNS notification

Examples

%Pigeon.APNS.Notification{
    __meta__: %Pigeon.Metadata{on_response: nil},
    collapse_id: nil,
    device_token: "device token",
    expiration: nil,
    id: nil, # Set on push response if nil
    payload: %{"aps" => %{"alert" => "push message"}},
    priority: nil,
    push_type: "alert",
    response: nil, # Set on push response
    topic: "com.example.YourApp"
}

Link to this section Functions

Link to this function

new(msg, token, topic \\ nil)

View Source

Specs

new(String.t() | map(), String.t(), String.t() | nil) :: t()

Returns an APNS.Notification struct with given message, device token, and topic (optional).

Push payload is constructed in the form of %{"aps" => %{"alert" => msg}}

Examples

iex> Pigeon.APNS.Notification.new("push message", "device token")
%Pigeon.APNS.Notification{
  __meta__: %Pigeon.Metadata{},
  device_token: "device token",
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"alert" => "push message"}},
  topic: nil
}
Link to this function

new(msg, token, topic, id)

View Source

Specs

new(String.t() | map(), String.t(), String.t(), String.t()) :: t()

Returns an APNS.Notification struct with given message, device token, topic, and message ID.

Push payload is constructed in the form of %{"aps" => %{"alert" => msg}}

Examples

iex> Pigeon.APNS.Notification.new("push message", "device token", "topic", "id_1234")
%Pigeon.APNS.Notification{
  collapse_id: nil,
  device_token: "device token",
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: "id_1234",
  payload: %{"aps" => %{"alert" => "push message"}},
  topic: "topic"
}
Link to this function

put_alert(notification, alert)

View Source

Specs

put_alert(t(), String.t() | map()) :: t()

Updates "alert" key in push payload.

This is the alert message displayed on the device.

Examples

iex> Pigeon.APNS.Notification.put_alert(%Pigeon.APNS.Notification{}, "push message")
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"alert" => "push message"}}
}
Link to this function

put_badge(notification, badge)

View Source

Specs

put_badge(t(), integer()) :: t()

Updates "badge" key in push payload.

This is the badge number displayed on the application.

Examples

iex> Pigeon.APNS.Notification.put_badge(%Pigeon.APNS.Notification{}, 5)
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"badge" => 5}}
}
Link to this function

put_category(notification, category)

View Source

Specs

put_category(t(), String.t()) :: t()

Updates "category" key in push payload.

Examples

iex> Pigeon.APNS.Notification.put_category(%Pigeon.APNS.Notification{}, "category")
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"category" => "category"}}
}
Link to this function

put_content_available(notification)

View Source

Specs

put_content_available(t()) :: t()

Sets "content-available" flag in push payload.

Used for silent notifications. When set, ensure alert, badge, and sound keys are not configured.

Examples

iex> Pigeon.APNS.Notification.put_content_available(%Pigeon.APNS.Notification{})
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"content-available" => 1}}
}
Link to this function

put_custom(notification, data)

View Source

Specs

put_custom(t(), %{required(String.t()) => term()}) :: t()

Puts custom data in push payload.

Examples

iex> n = Pigeon.APNS.Notification.new("test message", "device token")
iex> Pigeon.APNS.Notification.put_custom(n, %{"custom-key" => 1234})
%Pigeon.APNS.Notification{
  device_token: "device token",
  payload: %{"aps" => %{"alert" => "test message"}, "custom-key" => 1234}
}
Link to this function

put_mutable_content(notification)

View Source

Specs

put_mutable_content(t()) :: t()

Sets "mutable-content" flag in push payload.

Used for notification service extensions (such as displaying custom media).

Examples

iex> Pigeon.APNS.Notification.put_mutable_content(%Pigeon.APNS.Notification{})
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"mutable-content" => 1}}
}
Link to this function

put_sound(notification, sound)

View Source

Specs

put_sound(t(), String.t() | %{required(String.t()) => term()}) :: t()

Updates "sound" key in push payload.

Used for custom notification sounds. Value should be the name of the custom sound file in the application's binary.

Examples

iex> Pigeon.APNS.Notification.put_sound(%Pigeon.APNS.Notification{}, "custom.aiff")
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"sound" => "custom.aiff"}}
}

iex> Pigeon.APNS.Notification.put_sound(%Pigeon.APNS.Notification{}, %{
...>   "critical" => 1,
...>   "sound" => "default",
...>   "volume" => 1.0
...> })
%Pigeon.APNS.Notification{
  payload: %{
    "aps" => %{
      "sound" => %{
        "critical" => 1, 
        "sound" => "default",
        "volume" => 1.0
      }
    }
  }
}
Link to this function

put_target_content_id(notification, id)

View Source

Specs

put_target_content_id(t(), String.t()) :: t()

Updates "target-content-id" key in push payload.

Used for bringing a specific window forward.

Examples

iex> Pigeon.APNS.Notification.put_target_content_id(%Pigeon.APNS.Notification{}, "example")
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"target-content-id" => "example"}}
}
Link to this function

put_thread_id(notification, id)

View Source

Specs

put_thread_id(t(), String.t()) :: t()

Updates "thread-id" key in push payload.

Used for grouping related notifications.

Examples

iex> Pigeon.APNS.Notification.put_thread_id(%Pigeon.APNS.Notification{}, "example")
%Pigeon.APNS.Notification{
  payload: %{"aps" => %{"thread-id" => "example"}}
}