View Source Pigeon.APNS.Notification (Pigeon v1.6.3)

Defines APNS notification struct and constructor functions.

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.

Updates "interruption-level" key in push payload.

Sets "mutable-content" flag in push payload.

Updates "sound" key in push payload.

Types

@type response() :: nil | :success | Pigeon.APNS.Error.error_response() | :timeout

APNS push response

  • nil - Push has not been sent yet.
  • :success - Push was successfully sent.
  • Pigeon.APNS.Error.error_response/0 - Push attempted but server responded with error.
  • :timeout - Internal error. Push did not reach APNS servers.
@type t() :: %Pigeon.APNS.Notification{
  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{
    collapse_id: nil,
    device_token: "device token",
    expiration: nil,
    priority: nil,
    push_type: "alert",
    id: nil, # Set on push response if nil
    payload: %{"aps" => %{"alert" => "push message"}},
    response: nil, # Set on push response
    topic: "com.example.YourApp"
}

Functions

Link to this function

new(msg, token, topic \\ nil)

View Source
@spec 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{
  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
@spec 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
@spec 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{
  collapse_id: nil,
  device_token: nil,
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"alert" => "push message"}},
  topic: nil
}
Link to this function

put_badge(notification, badge)

View Source
@spec 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{
  collapse_id: nil,
  device_token: nil,
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"badge" => 5}},
  topic: nil
}
Link to this function

put_category(notification, category)

View Source
@spec 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{
  collapse_id: nil,
  device_token: nil,
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"category" => "category"}},
  topic: nil
}
Link to this function

put_content_available(notification)

View Source
@spec 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{
  collapse_id: nil,
  device_token: nil,
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"content-available" => 1}},
  topic: nil
}
Link to this function

put_custom(notification, data)

View Source
@spec 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{
  collapse_id: nil,
  device_token: "device token",
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"alert" => "test message"}, "custom-key" => 1234},
  topic: nil
}
Link to this function

put_interruption_level(notification, level)

View Source
@spec put_interruption_level(t(), String.t()) :: t()

Updates "interruption-level" key in push payload.

Used for managing time sensitive notifications

Examples

iex> Pigeon.APNS.Notification.put_interruption_level(%Pigeon.APNS.Notification{}, "time-sensitive")
%Pigeon.APNS.Notification{
  collapse_id: nil,
  device_token: nil,
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"interruption-level" => "time-sensitive"}},
  topic: nil
}
Link to this function

put_mutable_content(notification)

View Source
@spec 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{
  collapse_id: nil,
  device_token: nil,
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"mutable-content" => 1}},
  topic: nil
}
Link to this function

put_sound(notification, sound)

View Source
@spec put_sound(t(), String.t()) :: 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{
  collapse_id: nil,
  device_token: nil,
  expiration: nil,
  priority: nil,
  push_type: "alert",
  id: nil,
  payload: %{"aps" => %{"sound" => "custom.aiff"}},
  topic: nil
}