APNs feedback handler
On March 31 2021 AppleĀ® discontinued the
APNs legacy binary protocol. Therefore, the com.APNS
class is now
desupported. The documentation pages related to the APNS binary protocol are still provided
for information. Contact your support center, if you need to implement APNS with the new
HTTP/2-based provider API.
Starting with Genero V5.00, the com.APNS
classe will be removed from the
com
package.
The com.APNS
class can be used to implement a server application to query
the APNs feedback service.
Implement an APNs feedback handler to get a list of unregistered device tokens in order to stop sending push notification messages to these apps.
An SSL/TLS certificate needs to be defined in FGLPROFILE, as described in APNs SSL/TLS certificate.
IMPORT com
IMPORT security
IMPORT util
MAIN
DEFINE req com.TcpRequest
DEFINE resp com.TcpResponse
DEFINE feedback DYNAMIC ARRAY OF RECORD
timestamp INTEGER,
deviceToken STRING
END RECORD
DEFINE timestamp DATETIME YEAR TO SECOND
DEFINE i INTEGER
DEFINE data BYTE
LOCATE data IN MEMORY
TRY
LET req = com.TcpRequest.create( "tcps://feedback.push.apple.com:2196" )
CALL req.setKeepConnection(true)
CALL req.setTimeout(2)
CALL req.doRequest()
LET resp = req.getResponse()
CALL resp.getDataResponse(data)
DISPLAY "Feedback service has responded"
CALL com.APNS.DecodeFeedback(data,feedback)
FOR i=1 TO feedback.getLength()
LET timestamp = util.Datetime.fromSecondsSinceEpoch(feedback[i].timestamp)
DISPLAY "Device Token :",feedback[i].deviceToken, " Timestamp :", timestamp
END FOR
CATCH
CASE status
WHEN -15553 DISPLAY "Timeout: No feedback message"
WHEN -15566 DISPLAY "Operation failed :", sqlca.sqlerrm
WHEN -15564 DISPLAY "Server has shutdown"
OTHERWISE DISPLAY "ERROR :",status
END CASE
END TRY
END MAIN