Pigeon
iOS and Android push notifications for Elixir
Installation
Add pigeon as a mix.exs dependency:
def deps do
[{:pigeon, "~> 0.2.0"}]
end
GCM (Android)
Usage
- Create a notification packet.
data = %{ key1: "value1", key2: "value2" }
n = Pigeon.GCM.Notification.new(data, "your device token")
- Send the packet.
Pigeon.GCM.push(n, "your GCM api key")
APNS (Apple iOS)
Usage
- Create a notification packet.
n = Pigeon.APNS.Notification.new("your message", "your device token")
- Create an APNS connection, where
modecan be either:devor:prod
c = Pigeon.APNS.Connection.new(mode, "your_push_cert.pem", "your_push_key.pem")
- Send the packet.
Pigeon.APNS.push(n, c)
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.
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", %{
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-custom-key: %{
custom-value: 500
}
})