Chinaunix首页 | 论坛 | 博客
  • 博客访问: 533333
  • 博文数量: 142
  • 博客积分: 2966
  • 博客等级: 少校
  • 技术积分: 1477
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-07 22:37
文章分类

全部博文(142)

文章存档

2013年(3)

2012年(21)

2011年(53)

2010年(33)

2009年(32)

分类: Python/Ruby

2011-10-28 13:28:38

PyAPNs

A Python library for interacting with the Apple Push Notification service (APNs)

Installation

Either download the source from GitHub or use easy_install:

$ easy_install apns Sample usagefrom apns import APNs, 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) # Get feedback messages for (token_hex, fail_time) in apns.feedback_server.items(): # do stuff with token_hex and fail_time

For more complicated alerts including custom buttons etc, use the PayloadAlert class. Example:

alert = PayloadAlert("Hello world!", action_loc_key="Click me") payload = Payload(alert=alert, sound="default")

To send custom payload arguments, pass a dictionary to the custom kwarg of the Payload constructor.

payload = Payload(alert="Hello World!", custom={'sekrit_number':123}) Further Info

iOS Reference Library: Local and Push Notification Programming Guide

Credits

Written and maintained by Simon Whitaker at .

阅读(4024) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~