Pigeon
iOS and Android push notifications for Elixir
Installation
Add pigeon as a mix.exs dependency:
def deps do
[{:pigeon, "~> 0.3.0"}]
end
GCM (Android)
Usage
- Set your environment variables.
config :pigeon,
gcm_key: "your_gcm_key_here"
- Create a notification packet.
data = %{ key1: "value1", key2: "value2" }
n = Pigeon.GCM.Notification.new(data, "your device token (registration ID)")
- Send the packet.
Pigeon.GCM.push(n)
APNS (Apple iOS)
Usage
- Set your environment environment variables. See below for setting up your certificate and key.
config :pigeon,
apns_mode: :dev,
apns_cert: "cert.pem",
apns_key: "key_unencrypted.pem"
- Create a notification packet. Note: Your push topic is generally the app's bundle identifier.
n = Pigeon.APNS.Notification.new("your message", "your device token", "your push topic")
- Send the packet.
Pigeon.APNS.push(n)
Generating Your Certificate and Key .pem
In Keychain Access, right-click your push certificate and select "Export..."
Export the certificate as
cert.p12Click the dropdown arrow next to the certificate, right-click the private key and select "Export..."
Export the private key as
key.p12From a shell, convert the certificate.
openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12`Convert the key.
openssl pkcs12 -nocerts -out key.pem -in key.p12Remove the password from the key.
openssl rsa -in key.pem -out key_unencrypted.pemcert.pemandkey_unencrypted.pemcan now be used as the cert and key inPigeon.push, respectively. Set them in yourconfig.exs
Notifications with Custom Data
Notifications can contain additional information for the aps key with a map passed as an optional 3rd parameter (e.g. setting badge counters or defining custom sounds)
n = Pigeon.APNS.Notification.new("your message", "your device token", "your push topic", %{
badge: 5,
sound: "default"
})
Or define custom payload data with an optional 4th parameter:
n = Pigeon.APNS.Notification.new("your message", "your device token", "your push topic", %{}, %{
your-custom-key: %{
custom-value: 500
}
})