如何建立一个德尔福苹果推送通知提供商服务器 [英] How to build an Apple Push Notification provider server in Delphi
问题描述
我需要建立在Delphi提供商服务器通过APNS推送通知信息发送到我的iPhone应用程序。
I need to build a provider server in Delphi to send push notification messages to my iPhone app via APNS.
我已阅读,这是有可能通过Indy组件做。它也需要安装Apple提供的SSL证书(或.p12)。
I have read that this is possible to do through Indy components. It is also required to install an SSL certificate (.p12) provided by apple.
我在找一些指导与此在Delphi上手。
什么是用好图书馆,和有没有人知道任何例如code做这样的事情?
I'm looking for some pointers to get started with this in Delphi. What would be a good library to use, and does anyone know of any example code to do something like this?
下面是红宝石和放样品; PHP ,<一个href=\"http://stackoverflow.com/questions/1020762/does-anyone-know-how-to-write-an-apple-push-notification-provider-in-c\">C#和<一个href=\"http://stackoverflow.com/questions/9410249/ssl-handshake-with-apple-push-notification-server-via-java\">JAVA
推荐答案
确定我这个管理如下:结果
添加您的表单上的印 TidTCPClient
和 TIdSSLIOHandlerSocket
并链接它们。坐落在 TIdSSLIOHandlerSocket
,请将 CERTFILE
和 KeyFile时
到适当的质子交换膜的文件。设置方法 sslvSSLv23
键,模式切换为 sslmClient
。结果
在 IOHandler
的 OnGetPassword
事件设置你的密钥的密码。
OK I managed this as follows:
Add an indy TidTCPClient
and TIdSSLIOHandlerSocket
on your form and link them. Set the SSL options in the TIdSSLIOHandlerSocket
, set CertFile
and KeyFile
to the appropriate .pem files. Set method to sslvSSLv23
and mode to sslmClient
.
In the IOHandler
's OnGetPassword
event set your key's password.
有用的网址:
<一href=\"http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html\" rel=\"nofollow\">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应用程序发送的ID
N.b. HexData is the ID sent from the IPhone App
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;
这篇关于如何建立一个德尔福苹果推送通知提供商服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!