From 7dca6ec09bb39004687e846f3753e368ee003206 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 5 Nov 2013 12:38:03 +0100 Subject: [PATCH] Added content_available parameter to Payload object to support silent push notifications in iOS7 --- README.markdown | 7 +++++++ apns.py | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 1bf2bc1..9cd891c 100644 --- a/README.markdown +++ b/README.markdown @@ -41,6 +41,13 @@ of the Payload constructor. payload = Payload(alert="Hello World!", custom={'sekrit_number':123}) ``` +To send a **silent push notification** to an iOS 7 device, use the +content_available kwarg of the Payload constructor. + +```python +payload = Payload(content_available=1, sound="") +``` + ## Travis Build Status [![Build Status](https://secure.travis-ci.org/simonwhitaker/PyAPNs.png?branch=master)](http://travis-ci.org/simonwhitaker/PyAPNs) diff --git a/apns.py b/apns.py index 8c1f66f..1fa84a1 100644 --- a/apns.py +++ b/apns.py @@ -181,12 +181,14 @@ def __init__(self): class Payload(object): """A class representing an APNs message payload""" - def __init__(self, alert=None, badge=None, sound=None, custom={}): + def __init__(self, alert=None, badge=None, sound=None, custom={}, + content_available=False): super(Payload, self).__init__() self.alert = alert self.badge = badge self.sound = sound self.custom = custom + self.content_available = content_available self._check_size() def dict(self): @@ -203,6 +205,8 @@ def dict(self): d['sound'] = self.sound if self.badge is not None: d['badge'] = int(self.badge) + if self.content_available: + d['content-available'] = 1 d = { 'aps': d } d.update(self.custom)