TsgcWebPush_Client

The TsgcWebPush_Client is a class that allows you to send a notification once you obtain the subscription details. 

 

Find below an example of using the WebPush client to send a notification given an endpoint, public key and authentication secret from a WebPush subscription.

 


procedure SendWebPushNotification;
var
  oSubscription: TsgcHTTP_API_WebPush_PushSubscription;
  oWebPush: TsgcWebPush_Client ;
begin
  oSubscription := TsgcHTTP_API_WebPush_PushSubscription.Create;
  try
    oSubscription.Endpoint := 'endpoint';
    oSubscription.PublicKey := 'public key';
    oSubscription.AuthSecret := 'authentication secret';
    oWebPush := TsgcHTTP_API_WebPush_Client.Create(nil);
    try
      oWebPush.VAPID.PEM.PrivateKey.Text := 'private_key_pem';
      oWebPush.VAPID.DER.PrivateKey := 'private_key';
      oWebPush.VAPID.DER.PublicKey := 'public_key';
      oWebPush.SendNotification(oSubscription, '{"title": "eSeGeCe Notification", "body": "Hello from eSeGeCe!!!"}');
    finally
      oWebPush.Free;
    end;
  finally
    oSubscription.Free;
  end;
end;