... ... # 复用这个gateway_server apns.gateway_server.send_notification(token_hex, payload)
import time
from apns import APNs, Frame, Payload
apns = APNs(use_sandbox=True, cert_file='cert.pem', key_file='key.pem')
# Send a notification
token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)
# Send multiple notifications in a single transmission
frame = Frame()
identifier = 1
expiry = time.time()+3600
priority = 10
frame.add_item('b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87', payload, identifier, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)
# Get feedback messages
for (token_hex, fail_time) in apns.feedback_server.items():
# do stuff with token_hex and fail_time
对于更复杂的alerts,比如自定义按钮,可以使用PayloadAlert类
alert = PayloadAlert("Hello world!", action_loc_key="Click me")
payload = Payload(alert=alert, sound="default")
from apnsclient import *
# 可以使用Session对象来维持连接池
session = Session()
con = session.get_connection("push_sandbox", cert_file="sandbox.pem")
# 发送推送和得到反馈
messge = Message(["my", "device", "tokens"], alert="My message", badge=10)
# Send the message.
srv = APNs(con)
res = srv.send(message)
# Check failures. Check codes in APNs reference docs.
for token, reason in res.failed.items():
code, errmsg = reason
print "Device faled: {0}, reason: {1}".format(token, errmsg)
# Check failures not related to devices.
for code, errmsg in res.errors:
print "Error: ", errmsg
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有