Send push notifications to mobile iOS devices https://github.com/memrange/apn#readme

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by Hans-Christian Esperer
Maintained by hc@hcesperer.org


push-notify-apn is a library and command line utility that can be used to send push notifications to mobile devices running iOS. Push notifications are small messages that can be sent to apps on smart phones and tablets without the need to keep open a long lived TCP connection per app, dramatically reducing the power consumption in standby mode.

The library is still in an experimental state. Bug and success reports as well as feature and pull requests are very welcome.

Sending a message is as simple as:

let sandbox     = True -- Development environment
    maxParallel = 10   -- Number of parallel connections to
                       -- the APN Servers
session <- newSession "my.key" "my.crt"
    "/etc/ssl/ca_certificates.txt" sandbox
    maxParallel "my.bundle.id"
let payload = alertMessage "Title" "Hello From Haskell"
    message = newMessage payload
    token   = base16EncodedToken "the-token"
success <- sendMessage session token payload
print success

command line utility

The command line utility can be used for testing your app. Use like this:

sendapn -c ../apn.crt -k ../apn.key -a \
    /etc/ssl/certs/ca-certificates.crt -b your.bundle.id -s \
    -t your-token -m "Your-message"

The -s flag means “sandbox”, i.e., for apps that are deployed in a development environment.

You can also use an interactive mode, where messages are read from stdin in this format:


To use, invoke like this:

stack exec -- sendapn -k ~/greaselapn.key -c ~/greaselapn.crt -a /etc/ssl/cert.pem -b org.hcesperer.greasel -s -i

Do remove the -s flag when using the production instead of the sandbox environment.


apn.crt and apn.key are the certificate and private key of your APN certificate from apple. To extract them from a .p12 file, use openssl:

openssl pkcs12 -in mycredentials.p12 -out apn.crt -nokeys
openssl pkcs12 -in mycredentials.p12 -nodes -out apn.key -nocerts

ca-certificates.crt is a truststore that contains the root certificates that are used to verify the apn server’s server certificates.


  • Let the client send alerts with no title

  • Add “semigroups” as a dependency for older ghc versions

  • Remove version constraints for http2-client

  • Make compatible with latest http2-client-

  • Use http2-client- or greater
  • Detect http2 goaway frames and remove connections from the connection pool accordingly
  • Detect connection errors when sending messages and remove connections from the pool when they happen
  • Fix in the README: The parameter is not timeout, but parallelConnections

  • Bugfix: Close the cleanup thread when closing a session
  • Check if the certificates and key exist early, when the session is created
  • Catch IO errors and return a temporary failure instead
  • Depend explicitly on http2-client- for now

  • Add an interactive/scriptable mode where messages are read from stdin
  • Re-structure exports to improve readability of the documentation
  • Close connections in addition to sending http2 gtfo when idle time exceeded (needs http2-client-
  • Add a closeSession method
  • Close sessions when they are garbage collected

  • Filter out invalid token characters when hex encoded tokens are supplied
  • Clarify the documentation
  • Close the flow control thread when closing connections

  • Initial release
comments powered byDisqus