Safe Haskell | None |
---|---|
Language | Haskell2010 |
Apple Push Notification Service provider
Sending push notifications requires an "Apple Push Services" certificate and an Apple-provided device token.
Getting an APS Certificate
The APS certificate is produced in the iOS Provisioning Portal. Once you've
generated the certificate, you can download it from the Provisioning Portal.
It is usually named aps_production.cer
or aps_development.cer
.
The private key for the certificate can be extracted from Apple's Keychain
utility as a .p12
file.
Once you have both the certificate and private key, the following commands can be used to convert the certificate and private key files into the format required by this library.
openssl x509 -in aps_development.cer -inform DER -outform PEM -out cert.pem openssl pkcs12 -in key.p12 -out key.pem -nodes
Getting a Device Token
Device tokens are retrieved from Apple on the device itself by calling
the registerForRemoteNotifications
method of the UIApplication
object.
For more information, please see Apple's documentation here.
Credits
Originally based on a blog post by Teemu Ikonen, available here.
Synopsis
- data APNSConfig = APNSConfig {}
- gatewayLive :: String
- gatewayTest :: String
- feedbackLive :: String
- feedbackTest :: String
- data ApplePushMessage = ApplePushMessage {}
- checkFailLive :: FilePath -> FilePath -> IO [ByteString]
- checkFailTest :: FilePath -> FilePath -> IO [ByteString]
- withSocketSafe :: ProtocolNumber -> (Socket -> IO a) -> IO a
- checkFail :: String -> FilePath -> FilePath -> IO [ByteString]
- withAPNSSocket :: APNSConfig -> (SSL -> IO ()) -> IO ()
- sendApplePushMessage :: SSL -> ApplePushMessage -> IO ()
- tokenLength :: Num a => a
- maxPayloadLength :: Num a => a
- buildPDU :: ApplePushMessage -> Put
- splitBS :: ByteString -> [ByteString]
- getExpiryTime :: IO Word32
Documentation
data APNSConfig Source #
Instances
Eq APNSConfig Source # | |
Defined in Network.PushNotification.IOS (==) :: APNSConfig -> APNSConfig -> Bool # (/=) :: APNSConfig -> APNSConfig -> Bool # | |
Ord APNSConfig Source # | |
Defined in Network.PushNotification.IOS compare :: APNSConfig -> APNSConfig -> Ordering # (<) :: APNSConfig -> APNSConfig -> Bool # (<=) :: APNSConfig -> APNSConfig -> Bool # (>) :: APNSConfig -> APNSConfig -> Bool # (>=) :: APNSConfig -> APNSConfig -> Bool # max :: APNSConfig -> APNSConfig -> APNSConfig # min :: APNSConfig -> APNSConfig -> APNSConfig # | |
Read APNSConfig Source # | |
Defined in Network.PushNotification.IOS readsPrec :: Int -> ReadS APNSConfig # readList :: ReadS [APNSConfig] # readPrec :: ReadPrec APNSConfig # readListPrec :: ReadPrec [APNSConfig] # | |
Show APNSConfig Source # | |
Defined in Network.PushNotification.IOS showsPrec :: Int -> APNSConfig -> ShowS # show :: APNSConfig -> String # showList :: [APNSConfig] -> ShowS # |
gatewayLive :: String Source #
gatewayTest :: String Source #
data ApplePushMessage Source #
ApplePushMessage | |
|
checkFailLive :: FilePath -> FilePath -> IO [ByteString] Source #
checkFailTest :: FilePath -> FilePath -> IO [ByteString] Source #
withSocketSafe :: ProtocolNumber -> (Socket -> IO a) -> IO a Source #
withAPNSSocket :: APNSConfig -> (SSL -> IO ()) -> IO () Source #
Opens an APNS connection, runs the supplied action with the SSL socket, and closes the connection.
Example usage:
withAPNSSocket cfg $ \sslsocket -> sendApplePushMessage msg sslsocket
Note that in practice you should keep the SSL socket open and re-use it. From the Apple documentation: "APNs treats rapid connection and disconnection as a denial-of-service attack."
sendApplePushMessage :: SSL -> ApplePushMessage -> IO () Source #
Send a message through the SSL socket
tokenLength :: Num a => a Source #
maxPayloadLength :: Num a => a Source #
buildPDU :: ApplePushMessage -> Put Source #
splitBS :: ByteString -> [ByteString] Source #
getExpiryTime :: IO Word32 Source #