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.
Verstuur APNs-pushmeldingen vanuit Delphi via HTTP/2 naar api.push.apple.com. Ondersteunt zowel certificaatgebaseerde als token-gebaseerde (JWT ES256) authenticatie.
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.
TsgcHTTP2Client + TsgcHTTP_JWT_Client
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
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);
Twee samenwerkende componenten verzorgen APNs end-to-end — HTTP/2-framing en JWT-uitgifte.
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).
Voor legacy universal certificates stel je TLSOptions.CertFile + Password in en leeg je Authentication.Token.JWT. De TLS-handshake authenticeert de verbinding.
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.
Stel Request.CustomHeaders in voor apns-topic, apns-priority, apns-push-type, apns-collapse-id, apns-expiration volgens de documentatie van Apple.
Eén TLS-verbinding verstuurt duizenden pushes per minuut — HTTP/2-streams multiplexen de aanvragen. Bekijk Response.Status per aanroep voor de afleveringsresultaten.
Gebruik iohSChannel op Windows voor kernel-mode TLS (geen DLL's nodig) of iohOpenSSL voor cross-platform serverdeployments.
Gezaghebbende bronnen voor de API's die dit component implementeert.
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. | Openen | |
| Demoproject — Demos\20.HTTP_Protocol\07.Apple_Push_Notifications Direct uitvoerbaar voorbeeldproject. Zit in het sgcWebSockets-package — download de proefversie hieronder. | Openen | |
| Technisch document (PDF) Functies, snelstart, codevoorbeelden voor Delphi & C++ Builder en primaire bronreferenties — alleen dit component. | Openen | |
| Gebruikershandleiding (PDF) Uitgebreide handleiding die elk component in de bibliotheek behandelt. | Openen |