Adding apns-push-type header
This commit is contained in:
+4
-1
@@ -96,7 +96,10 @@ class APNsClient(object):
|
|||||||
json_str = json.dumps(notification.dict(), cls=self.__json_encoder, ensure_ascii=False, separators=(',', ':'))
|
json_str = json.dumps(notification.dict(), cls=self.__json_encoder, ensure_ascii=False, separators=(',', ':'))
|
||||||
json_payload = json_str.encode('utf-8')
|
json_payload = json_str.encode('utf-8')
|
||||||
|
|
||||||
headers = {}
|
headers = {
|
||||||
|
'apns-push-type': notification.push_type
|
||||||
|
}
|
||||||
|
|
||||||
if topic is not None:
|
if topic is not None:
|
||||||
headers['apns-topic'] = topic
|
headers['apns-topic'] = topic
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ class Payload(object):
|
|||||||
self.mutable_content = mutable_content
|
self.mutable_content = mutable_content
|
||||||
self.thread_id = thread_id
|
self.thread_id = thread_id
|
||||||
|
|
||||||
|
self.push_type = 'background'
|
||||||
|
if self.alert or self.badge is not None or self.sound is not None:
|
||||||
|
self.push_type = 'alert'
|
||||||
|
|
||||||
def dict(self) -> Dict[str, Any]:
|
def dict(self) -> Dict[str, Any]:
|
||||||
result = {
|
result = {
|
||||||
'aps': {}
|
'aps': {}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ def test_payload():
|
|||||||
},
|
},
|
||||||
'extra': 'something'
|
'extra': 'something'
|
||||||
}
|
}
|
||||||
|
assert payload.push_type == 'alert'
|
||||||
|
|
||||||
|
|
||||||
def test_payload_with_payload_alert(payload_alert):
|
def test_payload_with_payload_alert(payload_alert):
|
||||||
@@ -80,3 +81,21 @@ def test_payload_with_payload_alert(payload_alert):
|
|||||||
},
|
},
|
||||||
'extra': 'something'
|
'extra': 'something'
|
||||||
}
|
}
|
||||||
|
assert payload.push_type == 'alert'
|
||||||
|
|
||||||
|
|
||||||
|
def test_payload_with_background_push_type():
|
||||||
|
payload = Payload(
|
||||||
|
content_available=True, mutable_content=True,
|
||||||
|
category='my_category', url_args='args', custom={'extra': 'something'}, thread_id='42')
|
||||||
|
assert payload.dict() == {
|
||||||
|
'aps': {
|
||||||
|
'content-available': 1,
|
||||||
|
'mutable-content': 1,
|
||||||
|
'thread-id': '42',
|
||||||
|
'category': 'my_category',
|
||||||
|
'url-args': 'args',
|
||||||
|
},
|
||||||
|
'extra': 'something'
|
||||||
|
}
|
||||||
|
assert payload.push_type == 'background'
|
||||||
|
|||||||
Reference in New Issue
Block a user