| The APNS class / com.APNS methods | |
Encodes an APNS specific push notification message into a BYTE.
com.APNS.EncodeMessage( data BYTE, deviceToken STRING, json STRING, uuid STRING, expiration INTEGER, priority SMALLINT) RETURNING result INTEGER
This method builds the APNS push notification message into a BYTE variable, for a given device token.
You need to provide several parameters in order to build the push notification message:
LET json = '{"aps":{"alert":"Hello, world","sound":"default","badge":1,"content-available":1}}'
See APNS documentation for more details about the JSON content of a message.
LET uuid = security.RandomGenerator.createRandomString(4)The expiration parameter is a number of seconds since Unix Epoch. It defines the expiration date of the message if it can not be sent by the APNS server to the target devices. This parameter can be NULL, to indicate that there is no expiration date:
LET dt = CURRENT + INTERVAL (10) MINUTE TO MINUTE LET expiration = util.Datetime.toSecondsSinceEpoch(dt)The priority parameter can be used to define a priority for the push notification message. Typically, use a value of 10 for immediate, 5 for delayed. This parameter can be NULL. See APNS documentation for more details.
If there's an encoding error, the method will raise the exception -15566, with details in the SQLCA.SQLERRM register.
DEFINE push_data BYTE,
deviceTokenHexa STRING,
dt DATETIME YEAR TO FRACTION(3),
expiration INTEGER,
json_data STRING,
uuid STRING
LOCATE push_data IN MEMORY
LET deviceTokenHexa = "84e3................."
LET dt = CURRENT + INTERVAL (10) MINUTE TO MINUTE
LET expiration = util.Datetime.toSecondsSinceEpoch(dt)
LET json_date = util.JSON.stringify(...)
LET uuid = security.RandomGenerator.createRandomString(4)
CALL com.APNS.EncodeMessage(
push_data,
security.HexBinary.ToBase64(deviceTokenHexa),
json_data,
uuid,
expiration,
10
)
IF LENGTH(push_data) > 2000 THEN
-- Must reduce the message content...
RETURN FALSE
END IF
-- Do the TCP request with the push_data variable
...
For a complete example, see APNs push provider.