From 5e4a938cd2e24249f6345aac27ba783defa5a63f Mon Sep 17 00:00:00 2001 From: Karl Date: Tue, 2 Mar 2021 15:32:46 +0100 Subject: [PATCH] Add support for subtitle keys See https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification --- apns2/payload.py | 13 +++++++++++++ test/test_payload.py | 21 +++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/apns2/payload.py b/apns2/payload.py index 8dbe595..52cdd52 100644 --- a/apns2/payload.py +++ b/apns2/payload.py @@ -9,6 +9,9 @@ def __init__( title: Optional[str] = None, title_localized_key: Optional[str] = None, title_localized_args: Optional[List[str]] = None, + subtitle: Optional[str] = None, + subtitle_localized_key: Optional[str] = None, + subtitle_localized_args: Optional[List[str]] = None, body: Optional[str] = None, body_localized_key: Optional[str] = None, body_localized_args: Optional[List[str]] = None, @@ -19,6 +22,9 @@ def __init__( self.title = title self.title_localized_key = title_localized_key self.title_localized_args = title_localized_args + self.subtitle = subtitle + self.subtitle_localized_key = subtitle_localized_key + self.subtitle_localized_args = subtitle_localized_args self.body = body self.body_localized_key = body_localized_key self.body_localized_args = body_localized_args @@ -36,6 +42,13 @@ def dict(self) -> Dict[str, Any]: if self.title_localized_args: result['title-loc-args'] = self.title_localized_args + if self.subtitle: + result['subtitle'] = self.subtitle + if self.subtitle_localized_key: + result['subtitle-loc-key'] = self.subtitle_localized_key + if self.subtitle_localized_args: + result['subtitle-loc-args'] = self.subtitle_localized_args + if self.body: result['body'] = self.body if self.body_localized_key: diff --git a/test/test_payload.py b/test/test_payload.py index d768c5b..c56b742 100644 --- a/test/test_payload.py +++ b/test/test_payload.py @@ -7,8 +7,11 @@ def payload_alert(): return PayloadAlert( title='title', - title_localized_key='loc_k', - title_localized_args=['loc_a'], + title_localized_key='title_loc_k', + title_localized_args=['title_loc_a'], + subtitle='subtitle', + subtitle_localized_key='subtitle_loc_k', + subtitle_localized_args=['subtitle_loc_a'], body='body', body_localized_key='body_loc_k', body_localized_args=['body_loc_a'], @@ -21,8 +24,11 @@ def payload_alert(): def test_payload_alert(payload_alert): assert payload_alert.dict() == { 'title': 'title', - 'title-loc-key': 'loc_k', - 'title-loc-args': ['loc_a'], + 'title-loc-key': 'title_loc_k', + 'title-loc-args': ['title_loc_a'], + 'subtitle': 'subtitle', + 'subtitle-loc-key': 'subtitle_loc_k', + 'subtitle-loc-args': ['subtitle_loc_a'], 'body': 'body', 'loc-key': 'body_loc_k', 'loc-args': ['body_loc_a'], @@ -61,8 +67,11 @@ def test_payload_with_payload_alert(payload_alert): 'aps': { 'alert': { 'title': 'title', - 'title-loc-key': 'loc_k', - 'title-loc-args': ['loc_a'], + 'title-loc-key': 'title_loc_k', + 'title-loc-args': ['title_loc_a'], + 'subtitle': 'subtitle', + 'subtitle-loc-key': 'subtitle_loc_k', + 'subtitle-loc-args': ['subtitle_loc_a'], 'body': 'body', 'loc-key': 'body_loc_k', 'loc-args': ['body_loc_a'],