为推送通知添加声音

Add sound to push notifications

我正在使用 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
        )

问题是,通知没有声音。根据docs,收到通知时应该有额外的字段来执行声音。

如何操作?

有参数sound,例子

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