如何在没有通知消息的情况下使用FCM发送数据



我使用FCM为我的应用程序,它使用Django作为后端,由flutter编写的前端。在某些情况下,我可以从我的Django应用程序发送通知,它像预期的那样工作。所有我现在需要的是发送一些数据到颤振应用程序,它会在某种程度上表现,但不发送消息或通知给用户。

下面是我如何从Django后端发送通知:

from pyfcm import FCMNotification
push_service = FCMNotification(api_key="****")
def send_single_notification(deviceID,title,body):
try:
push_service = FCMNotification(api_key="****")
registration_id = deviceID
message_title = title
message_body = body
result = push_service.notify_single_device(
registration_id=registration_id, message_title=message_title, message_body=message_body)
except:
print("failed to send notification")
def send_multi_notification(list_of_ids,title,body):
try:
registration_ids = list_of_ids
message_title =title
message_body = body
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_title=message_title, message_body=message_body)
except:
print("failed to send notification")

只需要发送数据…

看起来您正在使用pyfcm,在这种情况下,您可以发送没有message_titlemessage_body的消息,如文档中的这个示例所示:

result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message, content_available=True)

最新更新