Remove APNS tokens from our database if we get an invalid token notification

(imported from commit 5ec3c053684f9574a31103e7821309de883baa82)
This commit is contained in:
Leo Franchi
2014-01-21 15:22:33 -05:00
parent 226d894257
commit c0d3b2fd89

View File

@@ -55,6 +55,10 @@ def send_apple_push_notification(user, alert, **extra_data):
for token, reason in ret.failed.items():
code, errmsg = reason
logging.warning("APNS: Failed to deliver APNS notification to %s, reason: %s" % (token, errmsg))
if code == 8:
# Invalid Token, remove from our database
logging.warning("APNS: Removing token from database due to above failure")
PushDeviceToken.objects.get(user=user, token=hex_to_b64(token)).delete()
# Check failures not related to devices.
for code, errmsg in ret.errors: