Giter Club home page Giter Club logo

apns4ex's Introduction

APNS

The library was inspired by Apns4erl

WIP

Installation

  1. Add apns to your list of dependencies in mix.exs:

    def deps do [{:apns, "~> 0.0.1"}] end

  2. Ensure apns is started before your application:

    def application do [applications: [:apns]] end

Using

  1. 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
  1. Start a :dev (for Apple sandbox server) or :prod (for Apple prod server) worker:
{:ok, pid} = APNS.start :dev
  1. 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!"

Handling APNS errors and feedback

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.

Structs

  • %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
]

apns4ex's People

Contributors

chvanikoff avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.