1616from .exceptions import APNSError , APNSUnsupportedPriority , APNSServerError
1717
1818
19- def _apns_create_socket (creds = None , application_id = None ):
20- if creds is None :
21- if not get_manager ().has_auth_token_creds (application_id ):
22- cert = get_manager ().get_apns_certificate (application_id )
23- creds = apns2_credentials .CertificateCredentials (cert )
24- else :
25- keyPath , keyId , teamId = get_manager ().get_apns_auth_creds (application_id )
26- # No use getting a lifetime because this credential is
27- # ephemeral, but if you're looking at this to see how to
28- # create a credential, you could also pass the lifetime and
29- # algorithm. Neither of those settings are exposed in the
30- # settings API at the moment.
31- creds = creds or apns2_credentials .TokenCredentials (keyPath , keyId , teamId )
19+ def _apns_create_socket (application_id = None ):
20+ if not get_manager ().has_auth_token_creds (application_id ):
21+ cert = get_manager ().get_apns_certificate (application_id )
22+ creds = apns2_credentials .CertificateCredentials (cert )
23+ else :
24+ keyPath , keyId , teamId = get_manager ().get_apns_auth_creds (application_id )
25+ # No use getting a lifetime because this credential is
26+ # ephemeral, but if you're looking at this to see how to
27+ # create a credential, you could also pass the lifetime and
28+ # algorithm. Neither of those settings are exposed in the
29+ # settings API at the moment.
30+ creds = apns2_credentials .TokenCredentials (keyPath , keyId , teamId )
3231 client = apns2_client .APNsClient (
3332 creds ,
3433 use_sandbox = get_manager ().get_apns_use_sandbox (application_id ),
@@ -59,9 +58,9 @@ def _apns_prepare(
5958
6059
6160def _apns_send (
62- registration_id , alert , batch = False , application_id = None , creds = None , ** kwargs
61+ registration_id , alert , batch = False , application_id = None , ** kwargs
6362):
64- client = _apns_create_socket (creds = creds , application_id = application_id )
63+ client = _apns_create_socket (application_id = application_id )
6564
6665 notification_kwargs = {}
6766
@@ -97,7 +96,7 @@ def _apns_send(
9796 )
9897
9998
100- def apns_send_message (registration_id , alert , application_id = None , creds = None , ** kwargs ):
99+ def apns_send_message (registration_id , alert , application_id = None , ** kwargs ):
101100 """
102101 Sends an APNS notification to a single registration_id.
103102 This will send the notification as form data.
@@ -112,7 +111,7 @@ def apns_send_message(registration_id, alert, application_id=None, creds=None, *
112111 try :
113112 _apns_send (
114113 registration_id , alert , application_id = application_id ,
115- creds = creds , ** kwargs
114+ ** kwargs
116115 )
117116 except apns2_errors .APNsException as apns2_exception :
118117 if isinstance (apns2_exception , apns2_errors .Unregistered ):
@@ -124,7 +123,7 @@ def apns_send_message(registration_id, alert, application_id=None, creds=None, *
124123
125124
126125def apns_send_bulk_message (
127- registration_ids , alert , application_id = None , creds = None , ** kwargs
126+ registration_ids , alert , application_id = None , ** kwargs
128127):
129128 """
130129 Sends an APNS notification to one or more registration_ids.
@@ -137,7 +136,7 @@ def apns_send_bulk_message(
137136
138137 results = _apns_send (
139138 registration_ids , alert , batch = True , application_id = application_id ,
140- creds = creds , ** kwargs
139+ ** kwargs
141140 )
142141 inactive_tokens = [token for token , result in results .items () if result == "Unregistered" ]
143142 models .APNSDevice .objects .filter (registration_id__in = inactive_tokens ).update (active = False )
0 commit comments