[英]django-push-notifications in Django Rest Framework
I'm trying to use django-push-notifications
library in my Django REST backend project.我正在尝试在我的 Django REST 后端项目中使用django-push-notifications
库。 I have used Firebase Cloud Messaging.我使用过 Firebase 云消息传递。 Here is the implementation;这是实现;
settings.py设置.py
PUSH_NOTIFICATIONS_SETTINGS = {
"FCM_API_KEY": "private key from FCM app"
}
views.py视图.py
user, created = User.objects.get_or_create(email=email, username=username)
if created:
GCMDevice.objects.create(registration_id="token", cloud_message_type="FCM", user=user)
models.py模型.py
@receiver(post_save, sender=Action)
def create_new_action(sender, instance, created, **kwargs):
if created:
devices = GCMDevice.objects.filter(Q(user=instance.admin)|Q(user__in=instance.users.all()))
msg = "New action is created in %s" % instance.name
devices.send_message(msg)
My question is what should registration_id
be while I'm creating the GCMDevice object for each registered user?我的问题是,当我为每个注册用户创建 GCMDevice 对象时, registration_id
应该是什么?
registration_id
come from your frontend registration_id
来自您的前端
actually you must have an api that get user(frontend) fcm token or get it(fcm token) in user registration or login api's实际上,您必须有一个 api 来获取用户(前端)fcm 令牌或在用户注册或登录 api 中获取它(fcm 令牌)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.