codedge-llc / pigeon

iOS and Android push notifications for Elixir
https://hex.pm/packages/pigeon
MIT License
606 stars 133 forks source link

APNS: Change the push_type easily #241

Open lgastler opened 1 year ago

lgastler commented 1 year ago

Is your feature request related to a problem? Please describe. When updating iOS LiveActivities via Push (docs) the push_type needs to be liveactivity. As far as I found, changing the push_type is only possible by creating Pigeon.APNS.Notification from scratch.

Like this (valid example for liveactivities):

notf = %Pigeon.APNS.Notification{
  id: nil,
  device_token: token,
  topic: "<your bundleID>.push-type.liveactivity",
  expiration: nil,
  priority: nil,
  push_type: "liveactivity",
  payload: %{
    "aps" => %{
      "timestamp" => System.system_time(:second),
      "event" => "update",
      "content-state" => %{
        "value" => 7
      },
    }
  }
}

Describe the solution you'd like Creating the struct from scratch is not really a problem, but it would be nice to change that f.e. using a utility function. This is not only helpful for liveactivities but different types of push below a list of valid push_types values for APNS (see docs)

laugehoyer commented 1 year ago

The struct function can handle this for you.

msg = %{
  "timestamp" => System.system_time(:second),
  "event" => "update",
  "content-state" => %{
  "value" => 7
}
notf = Pigeon.APNS.Notification.new(msg, device_token, topic) |> struct(push_type: "liveactivity")