Apple Push (APNs) para Delphi y C++ Builder | eSeGeCe

Apple Push Notifications

Send APNs push notifications from Delphi over HTTP/2 to api.push.apple.com. Supports both certificate-based and token-based (JWT ES256) authentication.

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.

Clase del componente

TsgcHTTP2Client + TsgcHTTP_JWT_Client

Protocolo

APNs HTTP/2

Plataformas

Windows, macOS, Linux, iOS, Android

Edición

Standard / Professional / Enterprise

Sign a JWT, POST the alert, watch HTTP/2 status

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);

Qué incluye

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.

Especificaciones y referencias

Authoritative sources for the APIs this component implements.

Documentación y Demos

Enlace directo a la referencia del componente, descarga el proyecto demo listo para ejecutar y la prueba gratuita.

Online Help — TsgcHTTP2Client Referencia completa de propiedades, métodos y eventos de este componente.
Demo Project — Demos\20.HTTP_Protocol\07.Apple_Push_Notifications Proyecto de ejemplo listo para ejecutar. Se incluye en el paquete sgcWebSockets — descarga la prueba gratuita más abajo.
Documento técnico (PDF) Características, inicio rápido, ejemplos de código para Delphi y C++ Builder y referencias de fuentes primarias — solo este componente.
Manual de usuario (PDF) Manual completo que cubre todos los componentes de la biblioteca.

Preguntas frecuentes sobre Apple Push

Preguntas habituales sobre el envío de notificaciones APNs desde Delphi y C++ Builder.

Combina un TsgcHTTP2Client (transporte HTTP/2) con un TsgcHTTP_JWT_Client (generación de tokens ES256). Configura el cliente JWT con tu key ID de APNs, tu team ID y tu clave privada .p8, enlázalo a HTTP2.Authentication.Token.JWT, establece la cabecera apns-topic, y luego envía por POST el payload JSON a https://api.push.apple.com/3/device/<token>.
Ambas. Para la autenticación basada en token, TsgcHTTP_JWT_Client genera JWTs ES256 a partir de tu clave AuthKey_*.p8 de Apple y los refresca automáticamente (Apple espera la rotación en menos de una hora). Para la autenticación heredada por certificado, establece TLSOptions.CertFile y Password y vacía Authentication.Token.JWT, de modo que el handshake TLS autentique la conexión.
Sí. TsgcHTTP2Client habla la API HTTP/2 de APNs que reemplazó al protocolo binario retirado. Una única conexión TLS multiplexa miles de pushes por minuto sobre streams HTTP/2, y lees Response.Status en cada llamada para los resultados de entrega. TLS funciona a través de Windows SChannel (iohSChannel) u OpenSSL (iohOpenSSL).
sgcWebSockets es compatible desde Delphi 7 hasta la última versión de Delphi y las versiones de C++ Builder correspondientes, en Windows, macOS, Linux, iOS y Android. Descarga la prueba gratuita para integrar Apple Push Notifications en tu propio proyecto.

Ready to Send APNs Pushes from Delphi?

Download the free trial and integrate Apple Push Notifications into your Delphi applications.