def _send_apns(registration_ids, message, **kwargs): ''' Send a message to one or more APNS recipients :param registration_ids: a single or iterable collection of registration ids (APNS tokens) :param message: the payload to send. This is sent as the value of the 'alert' APNS key :param kwargs: additional APNS arguments. See push_notifications.apns._apns_sendd ''' # Strip whitespace from APNS Registration Ids. This is also done on ingestion for new registration_ids registration_ids = [reg_id.replace(" ", "") for reg_id in registration_ids] enqueue_date_str = kwargs.pop('enqueue_date', None) try: if isinstance(registration_ids, collections.Iterable): apns_send_bulk_message(registration_ids, message, **kwargs) else: apns_send_message(registration_ids, message, **kwargs) log_message_sent(enqueue_date_str=enqueue_date_str) except Exception as exception: logger.exception("Exception sending APNS message. %s : %s" % (exception.__class__.__name__, str(exception))) # We log a 'message sent with exception' event as well as the full exception itself log_message_sent(exception=exception, enqueue_date_str=enqueue_date_str) analytics.exception()
def _send_apns(registration_ids, message, **kwargs): ''' Send a message to one or more APNS recipients :param registration_ids: a single or iterable collection of registration ids (APNS tokens) :param message: the payload to send. This is sent as the value of the 'alert' APNS key :param kwargs: additional APNS arguments. See push_notifications.apns._apns_sendd ''' enqueue_date_str = kwargs.pop('enqueue_date', None) try: if isinstance(registration_ids, collections.Iterable): apns_send_bulk_message(registration_ids, message, **kwargs) else: apns_send_message(registration_ids, message, **kwargs) log_message_sent(enqueue_date_str=enqueue_date_str) except Exception as exception: logger.exception("Exception sending APNS message. %s : %s" % (exception.__class__.__name__, str(exception))) # We log a 'message sent with exception' event as well as the full exception itself log_message_sent(exception=exception, enqueue_date_str=enqueue_date_str) analytics.exception()
def _send_apns(registration_ids, message, **kwargs): ''' Send a message to one or more APNS recipients :param registration_ids: a single or iterable collection of registration ids (APNS tokens) :param message: the payload to send. This is sent as the value of the 'alert' APNS key :param kwargs: additional APNS arguments. See push_notifications.apns._apns_sendd ''' # Strip whitespace from APNS Registration Ids. This is also done on ingestion for new registration_ids registration_ids = [reg_id.replace(" ", "") for reg_id in registration_ids] enqueue_date_str = kwargs.pop('enqueue_date', None) priority = 'low' if message.get('body', None) is not None: priority = 'high' try: if isinstance(registration_ids, collections.Iterable): apns_send_bulk_message(registration_ids, message, **kwargs) else: apns_send_message(registration_ids, message, **kwargs) log_message_sent(enqueue_date_str=enqueue_date_str, priority=priority) except Exception as exception: logger.exception("Exception sending APNS message. %s : %s" % (exception.__class__.__name__, str(exception))) # We log a 'message sent with exception' event as well as the full exception itself log_message_sent(exception=exception, enqueue_date_str=enqueue_date_str, priority=priority) analytics.exception()
def push_notification(user): notifications = Notification.objects.all() for notification in notifications: first_operand = str( Tag.objects.filter(name_ID=notification.first_operand)[0].value) operator = notification.operator second_operand = notification.second_operand user = notification.owner if second_operand == "true" or second_operand == "TRUE": second_operand = "1" elif second_operand == "false" or second_operand == "FALSE": second_operand = "0" if eval(first_operand + operator + second_operand): if not notification.sended: registration_id = user.apns_device_token message = { "title": notification.title, "body": notification.message } apns_send_message(registration_id, message) Notification.objects.filter(id=notification.id, owner=user).update(sended=True) else: Notification.objects.filter(id=notification.id, owner=user).update(sended=False)
def send_apns(registration_ids, message, **kwargs): ''' Send a message to one or more APNS recipients :param registration_ids: a single or iterable collection of registration ids (APNS tokens) :param message: the payload to send. This is sent as the value of the 'alert' APNS key :param kwargs: additional APNS arguments. See push_notifications.apns._apns_sendd ''' if isinstance(registration_ids, collections.Iterable): apns_send_bulk_message(registration_ids, message, **kwargs) else: apns_send_message(registration_ids, message, **kwargs)
def _send_apns(registration_ids, message, **kwargs): ''' Send a message to one or more APNS recipients :param registration_ids: a single or iterable collection of registration ids (APNS tokens) :param message: the payload to send. This is sent as the value of the 'alert' APNS key :param kwargs: additional APNS arguments. See push_notifications.apns._apns_sendd ''' try: if isinstance(registration_ids, collections.Iterable): apns_send_bulk_message(registration_ids, message, **kwargs) else: apns_send_message(registration_ids, message, **kwargs) except Exception as exception: logger.info("Exception sending APNS message: %s" % str(exception))
def send_message(self, message, increase_badge=False, **kwargs): if increase_badge: self.badge = self.badge + 1 self.save() kwargs['badge'] = self.badge return apns_send_message(registration_id=self.registration_id, alert=message, **kwargs)