This article describes how to set up an iPhone Push server instance for PHP to operate an iPhone Push server instance for PHP. Adding the Push function to an application is very helpful for users to obtain information in a timely manner. I have previously introduced the iPhone's Push (Push Notification) function principle analysis, this section describes how to add a Push function to your App and create a PHP Push server instance for the iPhone.
This article describes how to create a Push server instance for the iPhone in PHP. Adding the Push function to an application is very helpful for users to obtain information in a timely manner. I have previously introduced the iPhone's Push (Push Notification) function principle analysis, it mentioned that to add a push function for your App, developers must first build a push server. The following describes how to build a php push server for the iPhone application.
0. install XCode on Mac OS X and connect to a normal iPhone to maintain a peaceful attitude.
Basic settings for APP development
1. create the app id and Device in the iPhone Provisioning Portal.
2. Generate the Certificate Request CertificateSigningRequest. certSigningRequest in the Keychain Access. app (menu> Keychain Access> Certificate Assistant> Request a Certificate From a Certificate Authority ...).
3. Request a Certificate from iPhone Provisioning Portal> Certificates (click Request Certificate to upload CertificateSigningRequest. certSigningRequest ).
4. after the request is complete, download the certificate 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, and 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 the Enable for Apple Push Notification service, configure the Development Push SSL Certificate, and upload the 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.
A. Targets> $ APP_NAME> context menu> Properties> Identifier
Modify
Identifier
Is
App ID
B. Targets> $ APP_NAME> context menu> Build> Code Signing Identifier> Any iPhone OS Device
Specify the iPhone Developer as a development machine. after compilation and running, the device token is displayed on the iPhone.
Php Push Notification sender code:
DeviceToken = "device token ";
$ Body = array ("aps" => array
("Alert" => 'Message', "badge" => 1, "sound" => 'received5. caf '));
$ Ctx = stream_context_create ();
Stream_context_set_option ($ ctx, "ssl", "local_cert", "ck. pem ");
$ Fp = stream_socket_client
("Ssl: // gateway.sandbox.push.apple.com: 2195", $ err, $ errstr, 60, STREAM_CLIENT_CONNECT, $ ctx );
If (! $ Fp ){
Print "Failed to connect $ err $ errstrn ";
Return;
}
Print "Connection OK \ n ";
Payload = json_encode ($ body );
$ Msg = chr (0 ). pack ("n", 32 ). pack ("H *", $ deviceToken ). pack ("n", strlen ($ payload )). $ payload;
Rint "sending message:". $ payload. "\ n ";
Fwrite ($ fp, $ msg); fclose ($ fp );
?>
The content of the Push server instance operation for the PHP version of the iPhone has been introduced in the CJSen 2011-12-15 on the first floor. could you tell me if I want to send the same message to many devices? is there any interface or method to say: I sent all device IDs and a message from the server to apns. the Apple server automatically sends messages to each device, instead of sending messages one by one with a device ID on the server;
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.