Skip to content

Instantly share code, notes, and snippets.

@ikeikeikeike
Created July 28, 2012 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikeikeikeike/3193547 to your computer and use it in GitHub Desktop.
Save ikeikeikeike/3193547 to your computer and use it in GitHub Desktop.
apns check payload
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
@kroekchai1
Copy link

cm-171-101-116-22.revip11.asianet.co.th

@kroekchai1
Copy link

5gtestingontower

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment