为移动应用程序构建Rest应用程序。在应用程序中,用户可以启用/禁用声音和振动。我需要找到一种方法来禁用他们在防火墙云消息使用防火墙-管理包。
问题是- Firebase提供“声音”参数,该参数只接受声音资源的文件名。我没有看到任何选项来禁用它。此外,没有任何振动参数。
我希望编写如下代码:
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 根据大量的信息,这个代码可能会有所帮助。但我还没试过
发布于 2022-04-06 09:48:44
以上代码不起作用。我们不能关闭振动,通常消防基地使用系统电线选项来管理这一点。声音可以关掉:
Apple -发送“声音”参数Android中的空字符串发送不存在的文件名
https://stackoverflow.com/questions/71734609
复制相似问题