Add priority option for sending notification

This commit is contained in:
Sergey Petrov
2016-02-09 16:51:42 +03:00
parent 3f61fac159
commit 515bf64ae4
2 changed files with 9 additions and 5 deletions
+4 -2
View File
@@ -21,10 +21,12 @@ class APNsClient(object):
ssl_context.load_cert_chain(cert_file) ssl_context.load_cert_chain(cert_file)
self.__connection = HTTP20Connection(server, port, ssl_context=ssl_context) self.__connection = HTTP20Connection(server, port, ssl_context=ssl_context)
def send_notification(self, token_hex, notification, topic=None): def send_notification(self, token_hex, notification, prioriy=NotificationPriority.Immediate, topic=None):
json_payload = dumps(notification.dict(), ensure_ascii=False, separators=(',',':')).encode('utf-8') json_payload = dumps(notification.dict(), ensure_ascii=False, separators=(',',':')).encode('utf-8')
headers = {}
headers = {
'apns-priority': prioriy.value
}
if topic: if topic:
headers['apns-topic'] = topic headers['apns-topic'] = topic
+2
View File
@@ -1,5 +1,6 @@
from typing import Optional from typing import Optional
from apns2.client import NotificationPriority
from apns2.payload import Payload from apns2.payload import Payload
@@ -12,4 +13,5 @@ class APNsClient(object):
def send_notification(self, def send_notification(self,
token_hex: str, token_hex: str,
notification: Payload, notification: Payload,
prioriy: NotificationPriority = NotificationPriority.Immediate,
topic: Optional[str] = None) -> None: ... topic: Optional[str] = None) -> None: ...