In the previous blog, I show how retrieve a device token, now I will show how use the HTTP/2 sgcWebSockets client to send a notification (without the authentication part).
Send your remote notification payload and device token information to Apple Push Notification service (APNs).
How Connect to APNs
You must use HTTP/2 protocol and at least TLS 1.2 or later to establish a successful connection between your Server Provider and one of the following servers:
Development Server: https://api.sandbox.push.apple
Production Server: https://api.push.apple
Delphi Code
Create a new instance of TsgcHTTP2Client and call the method POST to send a notification to APNs.
oHTTP := TsgcHTTP2Client.Create(nil);
Try
// ... requires authorization code
oStream := TStringStream.Create('{"aps":{"alert":"Alert from sgcWebSockets!"}}');
Try
oHTTP.Post('https://api.push.apple/3/device/device_token', oStream);
if oHTTP.Response.Status = 200 then
ShowMessage('Notification Sent Successfully')
else
ShowMessage('Notification error');
Finally
oStream.Free;
End;
Finally
oHTTP.Free;
End;