From 1fee03c5ea96b35792350b78fe9b87729fb2d9af Mon Sep 17 00:00:00 2001 From: Derek Shockey Date: Thu, 31 Jan 2013 11:07:28 -0800 Subject: [PATCH] made PayloadAlert body parameter optional body and loc_key are mutually exclusive and body should be optional if loc_key is provided, otherwise the empty body takes up payload space which is already so constrained with APNs. --- apns.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apns.py b/apns.py index fdcec08..3113e43 100644 --- a/apns.py +++ b/apns.py @@ -142,7 +142,7 @@ def write(self, string): class PayloadAlert(object): - def __init__(self, body, action_loc_key=None, loc_key=None, + def __init__(self, body='', action_loc_key=None, loc_key=None, loc_args=None, launch_image=None): super(PayloadAlert, self).__init__() self.body = body @@ -152,11 +152,13 @@ def __init__(self, body, action_loc_key=None, loc_key=None, self.launch_image = launch_image def dict(self): - d = { 'body': self.body } + if not self.loc_key: + d = {'body': self.body} + else: + d = {'loc-key': self.loc_key} + if self.action_loc_key: d['action-loc-key'] = self.action_loc_key - if self.loc_key: - d['loc-key'] = self.loc_key if self.loc_args: d['loc-args'] = self.loc_args if self.launch_image: