OS apns-apple Notification Server and third party provider the principle of communication online has been a lot of introduction, here no longer introduced, there is want to know everyone can go to the iOS website https://developer.apple.com/ library/ios/documentation/networkinginternet/conceptual/remotenotificationspg/chapters/applepushservice.html#/ /APPLE_REF/DOC/UID/TP40008194-CH100-SW1 learn to learn. Online about iOS APNs to implement very little, generally Java or PHP, there is a C + + implementation, looked at, Then I want to use Erlang to achieve the communication with iOS APNs, in the effort to achieve, and share with you.-define (URL, "gateway.sandbox.push.apple.com").-define (port,2195).- Define (Device_token, "3BD9DBF509CD92D41A3334D8AB0FCCED1A6FC27C7C1BC60324B2BAFE1C15CADF"). Start ()->ssl:start ( ), Case Gen_tcp:connect (? Url? port,[binary],infinity) Of{ok,socket}->case ssl:connect (Socket,[{certfile, "./ios_app/pushchatcert.pem"},{ KeyFile, "./ios_app/pushchatkey.pem"},{password, "123456"}],infinity) Of{ok,sslsocket}->io:format ("# # # #socket Connect:~p~n ", [" OK "]), Command = <<0:8>>,token =? Device_token,devicelist = Change_16_to_10 (token,[]), Device = List_to_binary (devicelist), Io:format ("# #Device: ~p~n", [Device], Devicel = Length (devicelist), DevIcebin = <<devicel:16>>,message = "{\" aps\ ": {\" alert\ ": \" haha my test \ ", \" badge\ ": 4,\" sound\ ": \" Default\ "}}" , Messagel = Length (Message), Messagebin = <<messagel:16>>,data = List_to_binary ([command,devicebin,device , Messagebin,message]), Case ssl:send (sslsocket,data) Ofok->io:format ("##### #send ok!~n"); {Error,sreason}->io:format ("# # # #SReason: Send Error:~p~n", [Sreason]) end; {Error,reason}->io:format ("# # # #Reason: ~p~n", [Reason]) end; {Error,fre}->io:format ("#FRe: ~p~n", [FRe]) end. change_16_to_10 ([],l)->lists:reverse (L); Change_ 16_TO_10 ([h,t| tail],l)->first = Assci_to_10_type (H), Second = Assci_to_10_type (T), one = first * + second,change_16_to_10 (tail,[on e| L]). assci_to_10_type term >= $a andalso term =< $f->term-$a + 10;assci_to_10_type (term) When the term >= $A, the term =< $F->term-$A + 10;assci_to_10_type (term) when the term >= $0,term =< $9->term- $0;assci_to_10_type (_term)->0. communication with Apple APNsHow did the certificate come from? Refer to the iOS official documentation. Brief introduction: Requires iOS developer to provide to the server developer Aps_production.cer download from the Apple Developer website; then enter the following command in the terminal OpenSSL x509-in aps_production.cer- Inform Der-out Pushchatcert.pem get PUSHCHATCERT.PEM Double-click Install Aps_production.cer to keychain, find just installed push certificate in keychain, point open, right click Export Secret Want, Named Youkey.p12;demo is PUSHCHATKEY.P12 then enter the following command in the terminal OpenSSL pkcs12-nocerts-out pushchatkey.pem-in PUSHCHATKEY.P12 here need to enter the password, the password in the demo: 123456 Duplicate confirmation password, get PUSHCHATKEY.PEM code Http://pan.baidu.com/s/14GIEa