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"
입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-13(UTC)
[null,null,["최종 업데이트: 2025-08-13(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\"`."]]