Hello,
I'm using the following code to send Notifications to the Apple-APNs-Server. That works as expacted. Unfortunately after quitting I get a memory leak (2 x TsgcTCPNotifyObject). Any Ideas how to solve this?
Best Regards
I'm using the following code to send Notifications to the Apple-APNs-Server. That works as expacted. Unfortunately after quitting I get a memory leak (2 x TsgcTCPNotifyObject). Any Ideas how to solve this?
const
cURL = 'https://api.push.apple.com/3/device/';
function PushIt(const ADeviceToken: string; ABadge: Integer; const ATitle: string) : Boolean;
var
LHTTP : TsgcHTTP2Client;
LStream : TStringStream;
LPayLoad : string;
LTitle : string;
begin
Result := False;
LHTTP := TsgcHTTP2Client.Create(nil);
Try
LHTTP.TLSOptions.IOHandler := iohSChannel;
LHTTP.TLSOptions.CertFile := ExtractFilePath(ParamStr(0))+'Zertifikat.p12';
LHTTP.TLSOptions.Password := 'my_password';
LHTTP.TLSOptions.Version := tls1_2;
if ABadge < 0 then ABadge := 0;
if ABadge > 99 then ABadge := 99;
LTitle := ATitle;
if Trim(LTitle) = '' then LTitle := 'Info';
LPayLoad := Format('{ "aps" : { "alert" : { "title" : "%s" }, "badge" : %d } }',[ATitle, ABadge]);
LStream := TStringStream.Create(LPayLoad, TEncoding.UTF8);
Try
LHTTP.Request.CustomHeaders.Clear;
LHTTP.Request.CustomHeaders.Add('apns-topic: '+cAPNSTopic);
LHTTP.Post(cURL + ADeviceToken, LStream);
if LHTTP.Response.Status = 200 then begin
Result := True;
end;
Finally
LStream.Free;
End;
Finally
LHTTP.Free;
End;
end;
Best Regards