iOS推送通知的警报文本的最大长度是多少?
documentation规定了the notification payload has to be under 256 bytes in total,但肯定对警报文本有特定的字符限制。
发布于 2011-06-10 23:21:54
它应该是236个字节。据我所知,对警报文本的大小没有限制,但只有总有效载荷大小。因此,考虑到有效负载是最小的并且只包含警报信息,它应该如下所示:
{"aps":{"alert":""}}
这将占用20个字符(20个字节),剩下236个字节要放入警报字符串中。如果使用ASCII码,则长度为236个字符,如果使用UTF8和UTF16,则长度可能会更短。
发布于 2015-06-23 04:48:38
以下是一些屏幕截图(横幅、警报和通知中心)
发布于 2014-06-12 22:23:17
Apple push会基于各种原因拒绝字符串。我测试了推送交付的各种场景,这是我的有效修复(在python中):
# Apple rejects push payloads > 256 bytes (truncate msg to < 120 bytes to be safe)
if len(push_str) > 120:
push_str = push_str[0:120-3] + '...'
# Apple push rejects all quotes, remove them
import re
push_str = re.sub("[\"']", '', push_str)
# Apple push needs to newlines escaped
import MySQLdb
push_str = MySQLdb.escape_string(push_str)
# send it
import APNSWrapper
wrapper = APNSWrapper.APNSNotificationWrapper(certificate=...)
message = APNSWrapper.APNSNotification()
message.token(...)
message.badge(1)
message.alert(push_str)
message.sound("default")
wrapper.append(message)
wrapper.notify()
https://stackoverflow.com/questions/6307748
复制相似问题