def push_to_device(device: Device) -> apns2.Response: """Issue a `Blank Push` to a device. If the push token is invalid then it will be automatically set to None Args: device (Device): The device model to push to, must have a valid apns token and push magic Raises: ssl.SSLError [SSL: SSLV3_ALERT_CERTIFICATE_EXPIRED] sslv3 alert certificate expired (_ssl.c:777) if the push certificate has expired and the system attempts a push. Returns: APNS2Client Response object """ current_app.logger.debug( 'Sending a push notification to {} on topic {}, using push magic: {}'. format(device.hex_token, device.topic, device.push_magic)) client = get_apns() payload = MDMPayload(device.push_magic) notification = apns2.Notification(payload, priority=apns2.PRIORITY_LOW) response: apns2.response.Response = client.push(notification, device.hex_token, device.topic) # 410 means that the token is no longer valid for this device, so don't attempt to push any more if response.status_code == 410: device.token = None device.push_magic = None return response
def push_to_device(device: Device) -> apns2.Response: """Issue a `Blank Push` to a device. If the push token is invalid then it will be automatically set to None Args: device (Device): The device model to push to, must have a valid apns token and push magic Returns: APNS2Client Response object """ current_app.logger.debug('Sending a push notification to {} on topic {}, using push magic: {}'.format( device.hex_token, device.topic, device.push_magic )) client = get_apns() payload = MDMPayload(device.push_magic) notification = apns2.Notification(payload, priority=apns2.PRIORITY_LOW) response = client.push(notification, device.hex_token, device.topic) # 410 means that the token is no longer valid for this device, so don't attempt to push any more if response.status_code == 410: device.token = None device.push_magic = None return response