Anyone using Livecode Server for sending PushNotifications?
Jim Lambert
jiml at netrin.com
Thu Sep 25 13:29:59 EDT 2014
About a year ago I used John’s lcx files for doing push notifications and they worked beautifully.
If you only need to send a single notification to a single device here’s a variation on John’s script that will do it.
Jim Lambert
<?lc
include "includes/json.lc"
command sendNotification pDevice, pAlert, pBadge, pSound, pPayload
# Provide the Host Information.
local tHost = "gateway.sandbox.push.apple.com"
local tPort = 2195
# Provide the Certificate and Key Data.
local tCert = "AppCertKey.pem"
# Provide the Private Key Passphrase (alternatively you can keep this secrete and
# enter the key manually on the terminal -> remove relevant line from code).
# Replace XXXXX with your Passphrase
local tPassphrase = "XXXXX"
# create the notificaion
put pAlert into tBodyA["aps"]["alert"]
put pBadge into tBodyA["aps"]["badge"]
put pSound into tBodyA["aps"]["sound"]
put pPayload into tBodyA["payload"]
# convert to json - Mark Smith's library
put arrayToJson(tBodyA) into tNotification
# build the binary notification to send
repeat for each item tCode in "0,0,32"
put numToChar(tCode) after tBinary
end repeat
put binaryEncode("H*", tDevice) after tBinary
put binaryEncode("n", length(tNotification)) after tBinary
put tNotification after tBinary
# write the binary to a file and send via openssl
put (pDevice & the seconds) & ".bin" into tFile
put tBinary into URL("binfile:APNs/" & tFile)
get shell("cat APNs/" & tFile & " | openssl s_client -connect" && tHost & ":" & tPort && "-cert" && tCert && "-pass pass:" & tPassphrase)
end sendNotification
More information about the use-livecode
mailing list