Ответ 1
OK Мне это удалось:
Добавьте в форму форму indy TidTCPClient
и TIdSSLIOHandlerSocket
и свяжите их. Задайте параметры SSL в TIdSSLIOHandlerSocket
, установите CertFile
и KeyFile
в соответствующие файлы .pem. Установите метод sslvSSLv23
и режим sslmClient
.
В событии IOHandler
OnGetPassword
установите свой пароль для ключа.
Полезные URL: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
На фронте кодирования:
N.b. HexData - это идентификатор, отправленный из приложения IPhone
function SendNotification(HexData: String; Count: Integer): Boolean;
var
p_DataSize,
I: Integer;
p_payllen: Byte;
p_json : String;
p_sndmsg : String;
begin
// Delphi 6 so needed to create JSON by hand<br>
p_json := '{"aps":{';
if (Count > 0) then
begin
p_json := p_json + '"alert":"You Have ' + IntToStr(Count);
if (count = 1) then
p_json := p_json + ' Reminder'
else<br>
p_json := p_json + ' Reminders';
p_json := p_json + '","sound": "default",';
end;
p_json := p_json + '"badge":' + inttostr(Count) + '}}';
p_payllen := length(p_json);
// Hard code the first part of message as it never changes
p_sndmsg := chr(0) + chr(0) + chr(32);
// Convert hex string to binary data
p_DataSize := Length(HexData) div 2;
for I := 0 to p_DataSize-1 do
p_sndmsg := p_sndmsg + char(Byte(StrToInt('$' + Copy(HexData, (I*2)+1,
2))));
//Now need to add length of json string and string itself
p_sndmsg := p_sndmsg + chr(0) + Char(p_payllen) + p_json;
try
// According to Apple can't connect/disconnect for each message so leave open for later
if (not PushClient.Connected) then
PushClient.Connect;
PushClient.IOHandler.Send(p_sndmsg[1], length(p_sndmsg));
except
on e : exception do
Log_Error(e.message);
end;
end;