Created
July 28, 2012 14:09
-
-
Save ikeikeikeike/3193547 to your computer and use it in GitHub Desktop.
apns check payload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
def check_payload(string): | |
""" check payload | |
""" | |
if not isinstance(string, (str, unicode)): | |
return False | |
string = [string] | |
fmt = "!BH32sH%ds" | |
structify = lambda t, p: struct.pack(fmt % len(p), 0, 32, t, len(p), p) | |
binaryify = lambda t: t.decode('hex') | |
payload = ''.join(map( | |
lambda y: structify(*y), | |
((binaryify(t), json.dumps(p, separators=(',', ':'))) for t, p in zip([""], string)) | |
)) | |
return len(payload) <= 250 # return len(payload) <= 256 | |
# 下記でも可能 | |
import json | |
notifications = {'aps': { | |
'alert': "bucho", | |
'sound': 'default', | |
"badge": 10 | |
}} | |
len(json.dumps(notification)) > 256 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cm-171-101-116-22.revip11.asianet.co.th