Reprinted IPhone Push Service-Apple push notification service
(1) You need to create App ID without. * In the program portal (that means one cert for one app)
(2) generate a Certificate Signing Request from your Mac's keychain and save to disk
(3) Upload the certificatesigningrequest. certsigningrequest to the program Portal
(4) Wait for the generation of CERT (about 1 min). Download the certificate (aps_developer_identity.cer) from the program Portal
(5) Keep (or rename them if you want) These 2 files (steps 2 and 4) in a safe place. you might need the certificatesigningrequest. certsigningrequest file to request a production cert in the future or renew it again.
(6) Suppose you have imported the aps_assist_identity.cer to the keychain. then you have to export these new cert and the private key of this CERT (not the public key) and saved. p12 files.
(7) Then you use these commands to generate the CERT and key in Mac's terminal for PEM format (privacy enhanced mail security certificate)
OpenSSL PKCS12-clcerts-nokeys-out cert. pem-in CERT. p12
OpenSSL PKCS12-nocerts-out key. pem-in key. p12
(8) The CERT. PEM and key. pem files will be used by your own program communicating with apns.
(9) If you want to remove the passphase of Private Key in key. Pem, do this
OpenSSL RSA-in key. pem-out key. unencrypted. pem
Then combine the certificate and key
Cat cert. pem key. unencrypted. pem> CK. pem
But please set the File Permission of this unencrypted key by using chmod 400 and is only readable by root in a sever configuration.
(10) The testing apns is at SSL: // gateway.sandbox.push.apple.com: 2195
(11) For the source codes to push payload message to the apns, you can find them in the developer forum. this is the one that I used, for PHP. run this (after obtaining the device token from the testing device and with the iPhone Client Program Setup)
Php-F apns. php "My message" 2
Or if you put this PHP script and the CK. pem in a local web server, you can use this to test
Http: // 127.0.0.1/apns. php? Message = test % 20 from % 20 javacom & badge = 2 & Sound = received5.caf
Apns. php select all
<? PHP $ devicetoken = '02da851dxxxxxxxxb4f2b5bfxxxxxxxxce198270xxxxxxxx0d3dac72bc87cd60 '; // masked for security reason // passphrase for the private key (CK. PEM file) // $ pass = ''; // get the parameters from http get or from command line $ message =$ _ Get ['message'] or $ message = $ argv [1] or $ message = 'message received ed from javacom '; $ badge = (INT) $ _ Get ['badge'] or $ badge = (INT) $ argv [2]; $ sound = $ _ Get ['sound'] or $ sound = $ argv [3]; // construct the notification payload $ body = array (); $ body ['aps '] = array ('alert' => $ message );
If ($ badge)
$ Body ['aps '] ['badge'] = $ badge;
If ($ sound)
$ Body ['aps '] ['sound'] = $ sound;
/* End of resumable items */
$ CTX = stream_context_create ();
Stream_context_set_option ($ CTX, 'ssl ', 'local _ cert', 'ck. pem ');
// Assume the private key passphase was removed.
// Stream_context_set_option ($ CTX, 'ssl ', 'passphrase', $ pass );
$ Fp = stream_socket_client ('ssl: // gateway.sandbox.push.apple.com: 000000', $ err, $ errstr, 60, stream_client_connect, $ CTX );
If (! $ FP ){
Print "failed to connect $ err $ errstr \ n ";
Return;
}
Else {
Print "connection OK \ n ";
}
$ Payload = json_encode ($ body );
$ MSG = CHR (0 ). pack ("N", 32 ). pack ('H * ', str_replace ('','', $ devicetoken )). pack ("N", strlen ($ payload )). $ payload;
Print "sending message:". $ payload. "\ n ";
Fwrite ($ FP, $ MSG );
Fclose ($ FP );
?>
(12) for iPhone client program, you need to edit the bundle identifier to the app ID that you created and imported the new provisioning profile for that app ID to Xcode And iphone. then implement the following methods in appdelegate to build & go
Appdelegate. m select all
-(Void) applicationdidfinishlaunching :( uiapplication *) Application {
Nslog (@ "registering remote notications ");
// For beta 2
// [[Uiapplication sharedapplication] registerforremotenotifications];
[[Uiapplication sharedapplication] registerforremotenotificationtypes :( uiremotenotificationtypebadge | uiremotenotiftypetypesound)]; // for beta 3
// Other codes here
}
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {
Nslog (@ "% @", [[[launchoptions objectforkey: @ "uiapplicationlaunchoptionsremotenotificationkey"] objectforkey: @ "APs"] objectforkey: @ "alert"]);
Return yes;
}
-(Void) Application :( uiapplication *) Application didregisterforremotenotificationswithdevicetoken :( nsdata *) devicetoken {
Nslog (@ "devicetoken: % @", devicetoken );
}
-(Void) Application :( uiapplication *) Application didfailtoregisterforremotenotificationswitherror :( nserror *) error {
Nslog (@ "error in registration. Error: % @", error );
}
(13) Additional Tips
-The feedback Service is currently unavailable.
-Send your messages to gateway.sandbox.push.apple.com: 2195 during the beta period.
-Devices must be set up as new iPhones in iTunes in order to generate device tokens. Restoring from backup is not currently supported.
This is what I see: the PUSH Service includes the certificate creation details.DevelopmentGood things