我使用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_title
和message_body
的消息,如文档中的这个示例所示:
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message, content_available=True)