module Main where
import System
import System.IO
import qualified Data.ByteString as BS
import Control.Concurrent.Chan
import Control.Concurrent
import Text.JSON
import ApplePush
appVersion = 0.1
getMsgs t c = do
putStr "Message> "
hFlush stdout
m <- hGetLine stdin
writeChan c (NotificationServiceSend t (makeNotification (Just $ Left $ m) Nothing (Just "chime") Nothing))
getMsgs t c
notificationCallback :: DeviceToken -> NotificationCallbackChan -> IO ()
notificationCallback t c = do
msg <- readChan c
case msg of
(NotificationServerConnected srvChan) -> do
tid <- forkIO $ getMsgs t srvChan
return ()
_ -> return ()
notificationCallback t c
showUsage a v = do
putStrLn $ "Apple Push Test, Version " ++ (show v)
putStrLn $ "usage: " ++ a ++ " device_token(hex)"
start (device_token:a) = do
let token = hexTokenToByteString device_token
putStrLn $ "Device Token: " ++ (tokenToString token)
c <- newChan
connectToNotificationService "127.0.0.1" 2195 c
notificationCallback token c
main :: IO ()
main = do
args <- getArgs
prog <- getProgName
if length args < 1
then showUsage prog appVersion
else start args