Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:20:25+00:00 2026-06-05T08:20:25+00:00

I am integrating a Push Provider Server with the codes (php-apns) from google codes.

  • 0

I am integrating a Push Provider Server with the codes (php-apns) from google codes. Everything seems to be fine except the number of bytes per message.

The number of bytes per payload should be maximum 256 characters.

If some Chinse characters or UTF8 characters are sent. After JSON_enode, each character would occupy 6 bytes. Am I right ?

So the maximum number of UTF8 characters in each push message is around 38.

But … Whatsapp (iPhone application) uses PUSH too, but it can push more Chinese characters … in one push message ?

Any hint ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:20:27+00:00Added an answer on June 5, 2026 at 8:20 am

    Here is the solution to your problem:

    go to ~/APNS/Message.php

    and replace this function:

    public function getPayload() {...}
    

    with this:

    /**
     * Convert the message in a JSON-encoded payload.
     *
     * @throws ApnsPHP_Message_Exception if payload is longer than maximum allowed
     *         size and AutoAdjustLongPayload is disabled.
     * @return @type string JSON-encoded payload.
     */
    public function getPayload()
    {
        $sJSONString = preg_replace_callback('/\\\u([0-9a-f]{4})/i', 
                            function($matches) {
                                if (function_exists('mb_convert_encoding')) {
                                    return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
                                } else {
                                    //Slower conversion from UTF-16 to UTF-8 (BMP Only)
                                    //See: http://www.cl.cam.ac.uk/~mgk25/unicode.html
                                    $decimal_code = hexdec($matches[1]);
                                    $character = "";
                                    if ((0x7F & $decimal_code) == $decimal_code) {
                                        //UTF-8 1-byte aka ASCII
                                        $first_byte     = 0x7F & $decimal_code;
                                        $character      = chr($first_byte);
                                    } elseif ((0x7FF & $decimal_code) == $decimal_code) {
                                        //UTF-8 2-bytes
                                        $first_byte     = 0xC0 | (($decimal_code >> 6) & 0x1F);
                                        $second_byte    = 0x80 | ($decimal_code & 0x3F);
                                        $character      = chr($first_byte) . chr($second_byte);
                                    } elseif ((0xFFFF & $decimal_code) == $decimal_code) {
                                        //UTF-8 3-bytes
                                        $first_byte     = 0xE0 | (($decimal_code >> 12) & 0x0F);
                                        $second_byte    = 0x80 | (($decimal_code >> 6) & 0x3F);
                                        $third_byte     = 0x80 | ($decimal_code & 0x3F);
                                        $character      = chr($first_byte) . chr($second_byte) . chr($third_byte);
                                    }
                                    return $character;
                                }
                            },
                            json_encode($this->_getPayload()));
        $sJSONPayload = str_replace(
            '"' . self::APPLE_RESERVED_NAMESPACE . '":[]',
            '"' . self::APPLE_RESERVED_NAMESPACE . '":{}',
            $sJSONString
        );
        $nJSONPayloadLen = strlen($sJSONPayload);
    
        if ($nJSONPayloadLen > self::PAYLOAD_MAXIMUM_SIZE) {
            if ($this->_bAutoAdjustLongPayload) {
                $nMaxTextLen = $nTextLen = strlen($this->_sText) - ($nJSONPayloadLen - self::PAYLOAD_MAXIMUM_SIZE);
                if ($nMaxTextLen > 0) {
                    while (strlen($this->_sText = mb_substr($this->_sText, 0, --$nTextLen, 'UTF-8')) > $nMaxTextLen);
                    return $this->getPayload();
                } else {
                    throw new ApnsPHP_Message_Exception(
                        "JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " .
                        self::PAYLOAD_MAXIMUM_SIZE . " bytes. The message text can not be auto-adjusted."
                    );
                }
            } else {
                throw new ApnsPHP_Message_Exception(
                    "JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " .
                    self::PAYLOAD_MAXIMUM_SIZE . " bytes"
                );
            }
        }
    
        return $sJSONPayload;
    }
    

    Tada!
    now you will be able to receive long utf-8 message without problems.

    source

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm integrating Symfony DIC in a zend framework application, that's going fine except for
I'm integrating the Google Calendar API with jQuery DatePicker. My code works fine on
I want to implement real time push notifications from php to my project. i
Am integrating APNS in my iPhone app. I have walked through on Apple Push
I'm currently integrating information from a third party API into a wordpress site. What
hello all i have code from open source project that im integrating into my
Integrating RESTFUL api in my application. I've to use restful services in my new
While integrating a Django app I have not used before, I found two different
We are right now integrating Solr Search with one of the shopping cart application.
I am integrating a payment gateway; this is the first time I am integrating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.