Share a PHP version push server building process

Source: Internet
Author: User

From: http://www.cocoachina.com/bbs/read.php? Tid = 30410

 

BeginnerIPhoneDevelopment, After repeated verification, combined with the following two Tutorials:
Http://ameyashetti.wordpress.com/2009/07/31/apple-push-notification-service-tutorial/
Http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/

The following figure shows the PHP version push server construction process starting from scratch:
========================================================== ======================================
0. install on Mac OS XXcodeConnect to a normal iPhone to maintain a peaceful attitude

app development basic Settings
1. create the app ID and device in the iPhone provisioning portal.
2. in keychain access. the application generates a certificate request certificatesigningrequest. certsigningrequest (menu> keychain access> certificate assistant> request a certificate from a certificate authority ...).
3. in iPhone provisioning portal> certificates, request a certificate (Click request certificate to upload certificatesigningrequest. certsigningrequest ).
4. after the request is complete, the certificate download the file (pai_identity.cer) and double-click it to import it to the key chain.
5. on the iPhone provisioning portal> provisioning, create a profile, select the specified app ID and devices, and generate the profile.
6. download the generated profile as * _ profile. mobileprovision: double-click the file to load the profile to the iPhone.

Push notification service settings
7. On the iPhone provisioning portal> app IDs, select the app ID of the push service to go to configure.
8. Confirm enableApplePush notification service, configure development push SSL certificate,UploadThe certificate request generated in step 1.
9. Download the generated aps_developer_identity.cer to complete the push service configuration.
10. Double-click aps_developer_identity.cer and save it to the key chain.

Generate the Certificate file required by PHP push notification sender
11. In the keychain access. app, select the new certificate (Apple development push services *), export it to the desktop, and save it as certificates. p12.
12. Run the following command:

Copy code

  1. OpenSSL PKCS12-clcerts-nokeys-out cert. pem-in certificates. p12
  2. OpenSSL PKCS12-nocerts-out key. pem-in certificates. p12
  3. OpenSSL RSA-in key. pem-out key. unencrypted. pem
  4. Cat cert. pem key. unencrypted. pem> CK. pem


Get the device token required for PHP push notification Sender:
13. Create a view-based application project in $ project_nameappdelegate.m:
A. paste the followingCode:

Copy code

  1. -(Void) applicationdidfinishlaunching :( uiapplication *) app {
  2. // Other setup tasks here ....
  3. [Window addsubview: viewcontroller. View];
  4. [Self alertnotice: @ "" withmsg: @ "Initiating remote noticationss are active" canclebuttontitle: @ "OK" otherbuttontitle: @ ""];
  5. [[Uiapplication sharedapplication] registerforremotenotificationtypes :( uiremotenotificationtypealert | uiremotenotiftypetypebadge | uiremotenotiftypetypesound)];
  6. }
  7. -(Void) Application :( uiapplication *) app didregisterforremotenotificationswithdevicetoken :( nsdata *) devicetoken {
  8. // Nslog (@ "devtoken = % @", devicetoken );
  9. [Self alertnotice: @ "" withmsg: [nsstring stringwithformat: @ "devtoken = % @", devicetoken] canclebuttontitle: @ "OK" otherbuttontitle: @ ""];
  10. }
  11. -(Void) Application :( uiapplication *) app didfailtoregisterforremotenotificationswitherror :( nserror *) Err {
  12. Nslog (@ "error in registration. Error: % @", err );
  13. [Self alertnotice: @ "" withmsg: [nsstring stringwithformat: @ "error in registration. Error: % @", err] canclebuttontitle: @ "OK" otherbuttontitle: @ ""];
  14. }
  15. -(Void) alertnotice :( nsstring *) Title withmsg :( nsstring *) MSG canclebuttontitle :( nsstring *) cancletitle otherbuttontitle :( nsstring *) othertitle {
  16. Uialertview * alert;
  17. If ([othertitle isequaltostring: @ ""])
  18. Alert = [[uialertview alloc] initwithtitle: Title message: MSG delegate: Self cancelbuttontitle: cancletitle otherbuttontitles: nil, nil];
  19. Else
  20. Alert = [[uialertview alloc] initwithtitle: Title message: MSG delegate: Self cancelbuttontitle: cancletitle otherbuttontitles: othertitle, nil];
  21. [Alert show];
  22. [Alert release];
  23. }


B. Add in-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {Method

Copy code

  1. [Self alertnotice: @ "" withmsg: @ "Initiating remote noticationss are active" canclebuttontitle: @ "OK" otherbuttontitle: @ ""];
  2. [[Uiapplication sharedapplication] registerforremotenotificationtypes :( uiremotenotificationtypealert | uiremotenotiftypetypebadge | uiremotenotiftypetypesound)];


14. Project Settings
A. Targets> $ app_name> context menu> Properties> identifier
Change identifier to app ID
B. Targets> $ app_name> context menu> build> code signing identifier> any iPhone OS device
Specify the iPhone developer as the development Machine
15. After compilation and running, the device token will be displayed on the iPhone

16. php push notification sender code:

copy the Code

  1. $ devicetoken = "device token";
  2. $ body = array ("APs" => array ("alert" => 'message', "badge" => 1, "sound" => 'received5. CAF ');
  3. $ CTX = stream_context_create ();
  4. stream_context_set_option ($ CTX, "SSL", "local_cert", "Ck. pem");
  5. $ fp = stream_socket_client ("SSL: // gateway.sandbox.push.apple.com: 2195", $ err, $ errstr, 60, stream_client_connect, $ CTX);
  6. If (! $ FP) {
  7. Print "failed to connect $ err $ errstrn";
  8. return;
  9. }
  10. Print "connection OK \ n";
  11. $ payload = json_encode ($ body);
  12. $ MSG = CHR (0 ). pack ("N", 32 ). pack ("H *", $ devicetoken ). pack ("N", strlen ($ payload )). $ payload;
  13. Print "sending message:". $ payload. "\ n";
  14. fwrite ($ FP, $ MSG);
  15. fclose ($ FP);
  16. ?>


=========================================== ======================================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.