Firebase Cloud Messaging - 配置声音和振动

Firebase Cloud Messaging - configure sound and vibration

为移动应用构建 Rest Api。 在应用程序中,用户可以 enable/disable 声音和振动。 我需要找到一种使用 firebase-admin 包在 firebase 云消息传递中禁用它们的方法。

问题是 - Firebase 提供了 'sound' 参数,它只接受声音资源的文件名。 我没有看到任何禁用它的选项。 此外,没有任何振动参数。

我希望编写如下代码:

user_settings = UserSettings.objects.get(user=user)
notification = Notification(sound=user_settings.allow_sound, vibration=user_settings.allow_vibration, text=text, title=title)

是否可以发送静默通知?

更新

sound = 'default' if user.user_settings.notify_sound else ''
if user.user_settings.notify_vibration:
  vibration_kwargs = {'default_vibrate_timings': True}
else:
  vibration_kwargs = {'vibrate_timings_millis': [0, 0, 0]}
  # Custom timing to off vibration. According to documentation 
  # this array will produce zero duration time for vibration 
android = AndroidConfig(notification=AndroidNotification(sound=sound, **vibration_kwargs))
ios = APNSConfig(payload=APNSPayload(aps=Aps(sound=sound)))
notification = Notification(title='Some title', body='Some body')

message = Message(notification=notification, android=android, apns=ios)
# Then i send this message using fcm-django package 

根据 lots if 信息,此代码可能会有所帮助。但我还没有测试它

上面的代码不起作用。我们无法关闭振动,通常 firebase 使用系统线选项来管理它。可以关闭声音:

Apple - 在“声音”参数中发送空字符串 Android - 发送 non-exist 文件名