Apple Push Notifications - Send HTTP/2 notifications (Part 2/4)

· 기능

이전 블로그에서는 기기 토큰을 가져오는 방법을 보여드렸어요. 이번에는 HTTP/2 sgcWebSockets 클라이언트를 사용해 (인증 부분 없이) 알림을 보내는 방법을 보여드릴게요.

Apple Push Notification 서비스(APNs)에 원격 알림 페이로드와 기기 토큰 정보를 보내세요.

How Connect to APNs

You must use HTTP/2 protocol and at least TLS 1.2 or later to establish a successful connection between your Server Provider and one of the following servers:

Development Server: https://api.sandbox.push.apple

Production Server: https://api.push.apple

Delphi Code 

TsgcHTTP2Client의 새 인스턴스를 만들고 POST 메서드를 호출해 APNs로 알림을 보내세요.

oHTTP := TsgcHTTP2Client.Create(nil);
Try
  // ... requires authorization code
  oStream := TStringStream.Create('{"aps":{"alert":"Alert from sgcWebSockets!"}}');
  Try
    oHTTP.Post('https://api.push.apple/3/device/device_token', oStream);
    if oHTTP.Response.Status = 200 then
      ShowMessage('Notification Sent Successfully')
    else
      ShowMessage('Notification error');	
  Finally
    oStream.Free;
  End;
Finally
  oHTTP.Free;
End;