- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 Push Provider Server 与来自 google codes 的代码 (php-apns) 集成。除了每条消息的字节数外,一切似乎都很好。
每个负载的字节数最多应为 256 个字符。
如果发送一些中文字符或UTF8字符。在 JSON_enode 之后,每个字符将占用 6 个字节。我说得对吗?
所以每条推送消息的最大UTF8字符数在38个左右。
但是...Whatsapp(iPhone 应用程序)也使用 PUSH,但它可以在一条推送消息中推送更多汉字...?
有什么提示吗?
最佳答案
这是您的问题的解决方案:
转到 ~/APNS/Message.php
并替换这个函数:
public function getPayload() {...}
用这个:
/**
* 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;
}
多田!现在您将能够毫无问题地接收长的 utf-8 消息。
关于ios4 - 苹果推送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5775196/
是否可以为字符串对象定义代数? 例如: 苹果 + 苹果 = 2 个苹果 苹果 + 橙 = 橙 + 苹果 苹果 + 3.5 苹果 = 4.5 苹果 是否有内置函数可以做到这一点?是否有必要创建类结构?
我将为餐厅创建一个 iOS 应用程序,这样您就可以通过该应用程序轻松支付食物费用。所以看看苹果的规则: https://developer.apple.com/app-store/review/gui
当我通过在断点处停止来调试程序时,队列和堆栈显示为 size=0(当它们不是时),但其他变量(如 vector )工作正常。 MacOS 10.14.1 Mojave Cmake 3.12.3 Xco
我正在尝试在圆形图上重现圆形末端,但我自己无法解决。 我试过谷歌但找不到准确的术语来重新创建它。 任何人都可以引导我朝着正确的方向前进或告诉我我在寻找什么吗? 我想要一个看起来像这样的圆形图 http
出于某种原因,我的脚本拒绝直接从 Text Wrangler 运行,但在导入到终端时运行正常。 import math def main(): print("This program find
我在 mac 上,我写了很多 python 脚本。 每次我需要运行它们时,我都必须输入“python script_name.py”。有什么方法可以让我只需要键入“p script_name.py”吗
我刚刚在 Mac OS X (Snow Leopard) 上安装了 python 2.6,当我启动 IDLE 时它一直在退出! 我通过以下方式删除了所有 python 安装:rm -rf/Librar
北京时间12月18日晚间消息,据国外媒体报道,亚马逊、谷歌和苹果公司周三达成一项罕见的合作伙伴关系,旨在打造智能家居新标准,让消费者使用起来更方便。 当前,亚马逊、谷歌和苹果都在积极争抢智能家居用
我一直在研究我们是否可以创建一个应用程序,可以在苹果的 native 媒体播放器中播放 protected DRM 视频文件。但我可以收集到的是,苹果将不允许受 DRM 保护的视频文件通过媒体播放器进
个人开发者通常需要多长时间才能被接受加入开发者计划? 我今天付了微薄的钱,但我感到不耐烦。 最佳答案 第二天我就被录取了,感觉很棒。还带着我的照片和那封电子邮件;-) 关于iphone - 苹果 iP
我是 CIT 的理学学士学生。我有一个项目,我想在某种主机/客户端中使用 Java 小程序和 JDBC。 我的小程序在本地主机上正常工作,但是当我将其部署到 apache Web 服务器上时,我失去了
一周前,我在代码中编写了一个名为 getline 的函数,但该函数不起作用。从那时起,每当我将函数命名为 getline 并尝试编译它时,它都不起作用。如果我将函数名称更改为其他名称,它会再次起作用。
我在使用苹果时遇到问题 examples对于 vDSP。我尝试了所有这些,但最后我需要卷积样本。我什至无法通过链接器获取它: Undefined symbols for architecture i3
我正在尝试将 Apple map 集成到我的 iPhone 应用程序中,以显示两个位置之间的路线。但它不会显示任何路线,并且会简单地在控制台中打印大量消息。 我位于印度孟买。当我尝试在 iPhone
也许你们都看到了Apple’s HTML5 showcase .问题是,他们没有在网上提供任何可下载的内容,对吗? 有没有人找到像 theirs 这样的 360 示例?我们可以按原样下载和使用,而不是
friend 们,请帮忙! 我不知道如何做“wait.until”。 我将 Appium 与 UIAutomator 结合使用。 我的测试会等到新应用程序的页面加载完毕,并且文本字段中的“文本 1”将
Android 比较 2 个图像以使用位图代码并告诉水果类别是水果(苹果/香蕉)还是不是水果。 我有问题与 Bitmap 和 BitmapFactory 比较有运行时错误,我有问题的解决方案。 act
Apple 有一个特殊的 URL,可用于指向物理位置的超链接,触发本地 map 应用程序启动并呈现指定位置: http://maps.apple.com/?q=SEARCH According to
我正在使用 MKMapView 将本地 map 添加到我的 iOS 应用程序。我只想确定是否需要任何类型的身份验证 key 或应用程序 ID?我会将此应用程序上传到 Apple Store。 最佳答案
你好,我想在苹果 map 上做针点聚类。它的可能解决方案是什么。现在我的屏幕上显示了一个针点的苹果 map 。 Pin point分组后的代码是什么。提前致谢 最佳答案 在 map 上聚类/显示大量点
我是一名优秀的程序员,十分优秀!