The library was inspired by Apns4erl
WIP
-
Add apns to your list of dependencies in mix.exs:
def deps do [{:apns, "~> 0.0.1"}] end
-
Ensure apns is started before your application:
def application do [applications: [:apns]] end
- Config the APNS app
- Required APNS config will only include paths to certificates:
config :apns,
certfile: [
dev: "/path/to/dev_cert.pem",
prod: "/path/to/prod_cert.pem"
]
- Optional config is the following:
config :apns,
callback_module: APNS.Callback,
keyfile: nil,
cert_password: nil,
timeout: 30000,
feedback_timeout: 1200,
reconnect_after: 1000
- Start a :dev (for Apple sandbox server) or :prod (for Apple prod server) worker:
{:ok, pid} = APNS.start :dev
- Start pushing your PNs via APNS.push/1 and APNS.push/3:
message = %APNS.Message.new
message = message
|> Map.put(:token, "0000000000000000000000000000000000000000000000000000000000000000")
|> Map.put(:alert, "Hello world!")
|> Map.put(:badge, 42)
|> Map.put(:extra, %{
"var1" => "val1",
"var2" => "val2"
})
APNS.push pid, message
or
APNS.push pid, "0000000000000000000000000000000000000000000000000000000000000000", "Hello world!"
You can define callback handler module via config param callback_module
, the module should implement 2 functions: error/1
and feedback/1
. These functions will be called when APNS responds with error or feedback to the app. %APNS.Error
and %APNS.Feedback
structs are passed to the functions accordingly.
- %APNS.Message{}
defstruct [
id: nil,
expiry: 86400000,
token: "",
content_available: nil,
alert: "",
badge: nil,
sound: "default",
priority: 10,
extra: []
]
- %APNS.Error{}
defstruct [
message_id: nil,
status: nil,
error: nil
]
- %APNS.Feedback{}
defstruct [
time: nil,
token: nil
]