รับข้อความในแอปไคลเอ็นต์ Unity
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
รับและจัดการข้อความ
หากต้องการรับข้อความ แอปของคุณต้องกำหนดการเรียกกลับให้กับตัวแฮนเดิลเหตุการณ์ Firebase.Messaging.FirebaseMessaging.MessageReceived
MessageReceived
เหตุการณ์
การลบล้างการกำหนดการโทรกลับไปยัง
Firebase.Messaging.FirebaseMessaging.MessageReceived
จะช่วยให้คุณดำเนินการตามข้อความที่ได้รับและรับข้อมูลข้อความได้ ดังนี้
public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
UnityEngine.Debug.Log("From: " + e.Message.From);
UnityEngine.Debug.Log("Message ID: " + e.Message.MessageId);
}
ข้อความอาจแสดงข้อมูลขาเข้าประเภทต่างๆ โดยส่วนใหญ่
ข้อความจะส่งไปยังแอปหลังจากที่นักพัฒนาแอปเริ่มการดำเนินการ นอกจากนี้ ระบบยังส่งข้อความไปยังแอปเพื่อแสดงเหตุการณ์ที่ส่งข้อความ เหตุการณ์ข้อผิดพลาดในการส่งข้อความ และเหตุการณ์ที่ลบข้อความแล้วด้วย คุณสามารถแยกความแตกต่างของกิจกรรมพิเศษเหล่านี้ได้
โดยดูที่ฟิลด์ MessageType
ลบข้อความแล้ว
ส่งไปยังแอปเมื่อเซิร์ฟเวอร์FCMลบข้อความที่รอดำเนินการ
MessageType
จะเป็น "deleted_messages"
ระบบอาจลบข้อความในกรณีต่อไปนี้
มีข้อความจำนวนมากเกินไปที่จัดเก็บไว้ในเซิร์ฟเวอร์ FCM
ปัญหานี้อาจเกิดขึ้นเมื่อเซิร์ฟเวอร์ของแอปส่งข้อความจำนวนมากที่ยุบไม่ได้ไปยังเซิร์ฟเวอร์ FCM ขณะที่อุปกรณ์ออฟไลน์อยู่
อุปกรณ์ไม่ได้เชื่อมต่อมาเป็นเวลานาน และเซิร์ฟเวอร์ของแอปได้
ส่งข้อความไปยังแอปในอุปกรณ์นั้นเมื่อเร็วๆ นี้ (ภายใน 4 สัปดาห์ที่ผ่านมา)
ขอแนะนำให้แอปทำการซิงค์เต็มรูปแบบกับเซิร์ฟเวอร์ของแอป
หลังจากได้รับการเรียกนี้
ส่งเหตุการณ์
เรียกใช้เมื่อส่งข้อความต้นทางไปยัง FCM สำเร็จแล้ว
MessageType
จะเป็น "send_event"
ส่งข้อผิดพลาด
เรียกใช้เมื่อเกิดข้อผิดพลาดในการส่งข้อความต้นทาง
MessageType
จะเป็น "send_error"
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-03 UTC
[null,null,["อัปเดตล่าสุด 2025-09-03 UTC"],[],[],null,["Receive and handle messages\n\nTo receive messages, your app must assign a callback to the\n[Firebase.Messaging.FirebaseMessaging.MessageReceived](/docs/reference/unity/class/firebase/messaging/firebase-messaging#messagereceived)\nevent handler.\n\n`MessageReceived` Event\n\nBy overriding assigning a callback to\n[Firebase.Messaging.FirebaseMessaging.MessageReceived](/docs/reference/unity/class/firebase/messaging/firebase-messaging#messagereceived)\nyou can perform actions based on the received message and get the message data: \n\n```c#\npublic void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {\n UnityEngine.Debug.Log(\"From: \" + e.Message.From);\n UnityEngine.Debug.Log(\"Message ID: \" + e.Message.MessageId);\n}\n```\n\nMessages can represent different kinds of incoming data. Most commonly,\nmessages are sent to the app after being initiated by the developer. Messages\nare also sent to you app to represent message sent events, message send error\nevents, and messages deleted events. These special events can be differentiated\nby checking the `MessageType` field.\n\nMessages Deleted\n\nSent to your app when the FCM server deletes pending messages.\n`MessageType` will be `\"deleted_messages\"`. Messages may be deleted if:\n\n1. Too many messages are stored on the FCM server.\n\n This can occur when an app's servers send a bunch of non-collapsible\n messages to FCM servers while the device is offline.\n2. The device hasn't connected in a long time and the app server has\n recently (within the last 4 weeks) sent a message to the app on that\n device.\n\n It is recommended that the app do a full sync with the app\n server after receiving this call.\n\nSend Event\n\nCalled when an upstream message has been successfully sent to FCM.\n`MessageType` will be `\"send_event\"`.\n\nSend Error\n\nCalled when there was an error sending an upstream message.\n`MessageType` will be `\"send_error\"`."]]