Skip to content

Commit 3e9a191

Browse files
meteranPr0Ger
authored andcommitted
Adding apns-push-type header
1 parent fde28ab commit 3e9a191

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

apns2/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ def send_notification_async(self, token_hex: str, notification: Payload, topic:
9696
json_str = json.dumps(notification.dict(), cls=self.__json_encoder, ensure_ascii=False, separators=(',', ':'))
9797
json_payload = json_str.encode('utf-8')
9898

99-
headers = {}
99+
headers = {
100+
'apns-push-type': notification.push_type
101+
}
102+
100103
if topic is not None:
101104
headers['apns-topic'] = topic
102105

apns2/payload.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def __init__(
7777
self.mutable_content = mutable_content
7878
self.thread_id = thread_id
7979

80+
self.push_type = 'background'
81+
if self.alert or self.badge is not None or self.sound is not None:
82+
self.push_type = 'alert'
83+
8084
def dict(self) -> Dict[str, Any]:
8185
result = {
8286
'aps': {}

test/test_payload.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_payload():
5050
},
5151
'extra': 'something'
5252
}
53+
assert payload.push_type == 'alert'
5354

5455

5556
def test_payload_with_payload_alert(payload_alert):
@@ -80,3 +81,21 @@ def test_payload_with_payload_alert(payload_alert):
8081
},
8182
'extra': 'something'
8283
}
84+
assert payload.push_type == 'alert'
85+
86+
87+
def test_payload_with_background_push_type():
88+
payload = Payload(
89+
content_available=True, mutable_content=True,
90+
category='my_category', url_args='args', custom={'extra': 'something'}, thread_id='42')
91+
assert payload.dict() == {
92+
'aps': {
93+
'content-available': 1,
94+
'mutable-content': 1,
95+
'thread-id': '42',
96+
'category': 'my_category',
97+
'url-args': 'args',
98+
},
99+
'extra': 'something'
100+
}
101+
assert payload.push_type == 'background'

0 commit comments

Comments
 (0)