Apple Push Notifications

Verstuur APNs-pushmeldingen vanuit Delphi via HTTP/2 naar api.push.apple.com. Ondersteunt zowel certificaatgebaseerde als token-gebaseerde (JWT ES256) authenticatie.

TsgcHTTP2Client + TsgcHTTP_JWT_Client

Combineer TsgcHTTP2Client (HTTP/2-transport) met TsgcHTTP_JWT_Client (ES256-tokens uitgeven) om APNs aan te sturen — de combinatie die Apple aanbeveelt sinds het oude binaire protocol is uitgeschakeld.

Componentklasse

TsgcHTTP2Client + TsgcHTTP_JWT_Client

Protocol

APNs HTTP/2

Platforms

Windows, macOS, Linux, iOS, Android

Editie

Standard / Professional / Enterprise

Onderteken een JWT, POST de melding, bekijk de HTTP/2-status

Configureer TsgcHTTP_JWT_Client met je APNs ES256-privésleutel en key/team-ID's, koppel het aan TsgcHTTP2Client.Authentication.Token.JWT en POST daarna de JSON-payload naar /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);

Wat zit erin

Twee samenwerkende componenten verzorgen APNs end-to-end — HTTP/2-framing en JWT-uitgifte.

Token-gebaseerde authenticatie

ES256-JWT's ondertekend met je Apple AuthKey_*.p8-privésleutel. De JWT-client vernieuwt het token automatisch elke 40 minuten (Apple verwacht rotatie binnen het uur).

Certificaatgebaseerde authenticatie

Voor legacy universal certificates stel je TLSOptions.CertFile + Password in en leeg je Authentication.Token.JWT. De TLS-handshake authenticeert de verbinding.

Productie / sandbox

Wijs de URL naar api.push.apple.com voor productie of api.development.push.apple.com voor de sandbox — hetzelfde component, alleen een andere host.

apns-topic + headers

Stel Request.CustomHeaders in voor apns-topic, apns-priority, apns-push-type, apns-collapse-id, apns-expiration volgens de documentatie van Apple.

HTTP/2-multiplexing

Eén TLS-verbinding verstuurt duizenden pushes per minuut — HTTP/2-streams multiplexen de aanvragen. Bekijk Response.Status per aanroep voor de afleveringsresultaten.

SChannel of OpenSSL

Gebruik iohSChannel op Windows voor kernel-mode TLS (geen DLL's nodig) of iohOpenSSL voor cross-platform serverdeployments.

Specificaties & referenties

Gezaghebbende bronnen voor de API's die dit component implementeert.

Documentatie & demo's

Deep-link naar de componentreferentie, pak het direct uitvoerbare demoproject en download de proefversie.

Online help — TsgcHTTP2Client Volledige property-, methode- en event-referentie voor dit component.
Demoproject — Demos\20.HTTP_Protocol\07.Apple_Push_Notifications Direct uitvoerbaar voorbeeldproject. Zit in het sgcWebSockets-package — download de proefversie hieronder.
Technisch document (PDF) Functies, snelstart, codevoorbeelden voor Delphi & C++ Builder en primaire bronreferenties — alleen dit component.
Gebruikershandleiding (PDF) Uitgebreide handleiding die elk component in de bibliotheek behandelt.

Klaar om APNs-pushes vanuit Delphi te versturen?

Download de gratis proefversie en integreer Apple Push Notifications in je Delphi-toepassingen.