TsgcWebPush_Client

TsgcWebPush_Client è una classe che consente di inviare una notifica una volta ottenuti i dettagli di sottoscrizione.

Introduzione

TsgcWebPush_Client è una classe che consente di inviare una notifica una volta ottenuti i dettagli di sottoscrizione.

 

Di seguito è riportato un esempio di utilizzo del client WebPush per inviare una notifica dato un endpoint, una chiave pubblica e un segreto di autenticazione da una sottoscrizione WebPush.

 


    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;
    

 

Riferimento