Apple Push Notifications

Envoie des notifications push APNs depuis Delphi sur HTTP/2 vers api.push.apple.com. Prend en charge l'authentification par certificat et par token (JWT ES256).

TsgcHTTP2Client + TsgcHTTP_JWT_Client

Pair TsgcHTTP2Client (HTTP/2 transport) with TsgcHTTP_JWT_Client (ES256 token minting) to drive APNs — the combo Apple recommends since the legacy binary protocol was retired.

Classe du composant

TsgcHTTP2Client + TsgcHTTP_JWT_Client

Protocole

APNs HTTP/2

Plateformes

Windows, macOS, Linux, iOS, Android

Édition

Standard / Professional / Enterprise

Signe un JWT, POSTe l'alerte, surveille le statut HTTP/2

Configure TsgcHTTP_JWT_Client with your APNs ES256 private key and key/team IDs, link it to TsgcHTTP2Client.Authentication.Token.JWT, then POST the JSON payload to /3/device/<token>.

uses
  sgcHTTP, sgcBase_Helpers;

var
  HTTP2: TsgcHTTP2Client;
  JWT: TsgcHTTP_JWT_Client;
begin
  JWT := TsgcHTTP_JWT_Client.Create(nil);
  JWT.JWTOptions.Header.alg := jwtES256;
  JWT.JWTOptions.Header.kid := 'APPLE-KEY-ID';
  JWT.JWTOptions.Payload.iss := 'APPLE-TEAM-ID';
  JWT.JWTOptions.Payload.iat := StrToInt64(GetDateTimeUnix(Now, False));
  JWT.JWTOptions.Algorithms.ES.PrivateKey.LoadFromFile('AuthKey_XXX.p8');
  JWT.JWTOptions.RefreshTokenAfter := 40 * 60;

  HTTP2 := TsgcHTTP2Client.Create(nil);
  HTTP2.TLSOptions.IOHandler := iohSChannel;
  HTTP2.Authentication.Token.JWT := JWT;
  HTTP2.Request.CustomHeaders.Clear;
  HTTP2.Request.CustomHeaders.Add('apns-topic: com.example.app');

  HTTP2.Post(
    'https://api.push.apple.com/3/device/',
    '{"aps":{"alert":"hello","sound":"default"}}');
end;
// uses: sgcHTTP
TsgcHTTP_JWT_Client *JWT = new TsgcHTTP_JWT_Client(this);
JWT->JWTOptions->Header->alg = jwtES256;
JWT->JWTOptions->Header->kid = "APPLE-KEY-ID";
JWT->JWTOptions->Payload->iss = "APPLE-TEAM-ID";
JWT->JWTOptions->Algorithms->ES->PrivateKey->LoadFromFile("AuthKey_XXX.p8");

TsgcHTTP2Client *HTTP2 = new TsgcHTTP2Client(this);
HTTP2->Authentication->Token->JWT = JWT;
HTTP2->Request->CustomHeaders->Add("apns-topic: com.example.app");
HTTP2->Post("https://api.push.apple.com/3/device/", payload);

Ce qu’il y a à l’intérieur

Two cooperating components handle APNs end-to-end — HTTP/2 framing and JWT minting.

Token-based auth

ES256 JWTs signed with your Apple AuthKey_*.p8 private key. The JWT client refreshes the token automatically every 40 minutes (Apple expects rotation within an hour).

Certificate-based auth

For legacy universal certificates, set TLSOptions.CertFile + Password and clear Authentication.Token.JWT. The TLS handshake authenticates the connection.

Production / Sandbox

Point the URL at api.push.apple.com for production or api.development.push.apple.com for the sandbox — same component, just a different host.

apns-topic + headers

Set Request.CustomHeaders for apns-topic, apns-priority, apns-push-type, apns-collapse-id, apns-expiration per Apple's documentation.

HTTP/2 multiplexing

A single TLS connection sends thousands of pushes per minute — HTTP/2 streams multiplex the requests. Inspect Response.Status per call for delivery results.

SChannel or OpenSSL

Use iohSChannel on Windows for kernel-mode TLS (no DLLs needed) or iohOpenSSL for cross-platform server deployments.

Spécifications et références

Sources de référence pour les APIs implémentées par ce composant.

Documentation et démos

Lien direct vers la référence du composant, récupère le projet de démo prêt à exécuter et télécharge l’essai.

Aide en ligne — TsgcHTTP2Client Référence complète des propriétés, méthodes et événements de ce composant.
Projet de démo — Demos\20.HTTP_Protocol\07.Apple_Push_Notifications Projet d’exemple prêt à exécuter. Livré dans le paquet sgcWebSockets — télécharge l’essai ci-dessous.
Document technique (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
Manuel utilisateur (PDF) Manuel exhaustif couvrant chaque composant de la bibliothèque.

Prêt à envoyer des push APNs depuis Delphi ?

Télécharge l'essai gratuit et intègre Apple Push Notifications à tes applications Delphi.