简体   繁体   English

为推送通知添加声音

[英]Add sound to push notifications

I'm using django-push-notifications to send push to our ios users (using APNS).我正在使用django-push-notifications向我们的 ios 用户发送推送(使用 APNS)。

from push_notifications.models import APNSDevice, APNSDeviceQuerySet

from apps.notifications.db.models import Notification
from apps.users.db.models import User


class APNSService:
    def __init__(self, user: User, title: str, body: str, data: dict):
        self.user = user
        self.title = title
        self.body = body
        self.data = data

    def get_devices(self) -> APNSDeviceQuerySet:
        return APNSDevice.objects.filter(user=self.user)

    def send_message(self):
        return self.get_devices().send_message(
            message=dict(
                title=self.title,
                body=self.body
            ),
            badge=Notification.objects.filter(recipient=self.user, unread=True).count(),
            extra=self.data
        )

The problem is, that notifications comes without a sound.问题是,通知没有声音。 According to the docs , there should be extra field to execute the sound when notification is received.根据文档,收到通知时应该有额外的字段来执行声音。

How to do this?这该怎么做?

There is param sound , example有参数sound ,例子

def send_message(self):
    return self.get_devices().send_message(
        message=dict(
            title=self.title,
            body=self.body
        ),
        extra=self.data,
        sound="default",
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM