IOS message push

Source: Internet
Author: User
In the afternoon, I changed the certificate and URL address of the IOS message push interface to the official one. An error occurred while testing the push message... In the afternoon, replace the certificate and URL of the IOS message push interface with the official one. An error occurred while testing and pushing messages...

When using the test certificate and URL Test, everything works normally. Apple imposes some restrictions on the interface.

Two minor changes were made to the message push interface based on the reported exception:

1. temporarily set the maximum time allowed for php script execution
set_time_limit(0);
2. after each device...
sleep(5);
The reason for setting sleep is to avoid frequent reading of Apple interfaces in a short time, resulting in link interruption. 5 seconds, I think it is a little long. please make proper adjustments later.

Then I tested the interface and pushed 20 messages to the device consecutively. the device successfully received 20 message prompts, and everything was normal.

Supplement:

According to the changes made yesterday, I tested it again today. it is no problem to send a single device contact. However, after obtaining the token information of all devices from the server, the following error occurs when pushing information cyclically for these settings:
Warning: fwrite() [function.fwrite]: SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry in /home/75/api/controller/iospush.class.php on line 102 Warning: fwrite() [function.fwrite]: SSL: Broken pipe in /home/75/api/controller/iospush.class.php on line 102
I searched for solutions to these problems on Google. I learned the following from some suggestions:

1. add two stream_context_set_option operations on the original base:
stream_context_set_option($ctx, 'ssl', 'allow_self_signed', true);stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
After adding:
$ctx = stream_context_create();stream_context_set_option($ctx, 'ssl', 'allow_self_signed', true);stream_context_set_option($ctx, 'ssl', 'verify_peer', false);stream_context_set_option($ctx, 'ssl', 'local_cert', $pem_path);stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
After the test, a single device is successfully pushed 20 times in a row. after reading all the device information from the server, the device is pushed. only the first few messages are successfully pushed, but all subsequent messages fail.

2. try to change the SSL version:

Put:
$fp = stream_socket_client("ssl://gateway.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
Changed:
$fp = stream_socket_client("sslv3://gateway.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
After the test, a single device is successfully sent continuously. Because the push operation is a formal push operation, in order not to affect the user, the push operation is not performed on all devices. Supplement later

Supplement:

It seems that the problem has been found. it should be in the device-token of the user stored on the server. some data is useless, that is, there are user data that has been detached from the APP, this requires that the device-token information on your server be updated regularly through the Apple APNS feedback service to ensure that all the data stored on the server is useful. Testing to use the feedback service to delete useless data...

Supplement:

On the basis of the original modification, the following modifications were made:

1. use the feedback service to regularly update the device_token information of the database (delete useless token values ).

2. obtain all device_token information, group it, and push it in batches. After each batch of push, the SSL link is disconnected, sleep for N seconds, and the SSL link is re-linked for the next batch of push. In this case, the data volume is not large. Therefore, the system obtains all device_token information from the database and then groups the information. Instead, it does not obtain data from the database in batches.

3. restrict the length of the pushed content. The length limit is because the Apple server can only receive 7000 bytes of push messages at a time, and each message must be less than 256 bytes.

4. add a push progress bar to display the push progress.

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.