Na primeira inicialização do app, o SDK do FCM gera um token
de registro para a instância do app cliente. Para segmentar dispositivos individuais ou criar grupos de dispositivos para o FCM, acesse esse token.
As mensagens podem representar diferentes tipos de dados recebidos. Geralmente, as mensagens são enviadas para o app após serem iniciadas pelo desenvolvedor. Elas também são enviadas ao seu app para representar eventos relacionados a mensagens enviadas, a erros de envio de mensagem e também a mensagens excluídas. Marque o campo Message::message_type para diferenciar esses eventos especiais.
Mensagens excluídas
Enviadas para seu app quando o servidor do FCM exclui as mensagens pendentes.
Message::message_type será "deleted_messages". As mensagens podem ser excluídas devido
aos seguintes fatores:
Há muitas mensagens armazenadas no servidor do FCM.
Isso pode ocorrer quando os servidores de um app enviam muitas mensagens não recolhíveis
para servidores do FCM enquanto o dispositivo está off-line.
O dispositivo ficou muito tempo sem se conectar, e o servidor do app enviou
uma mensagem recentemente (nas últimas quatro semanas) ao app nesse
dispositivo.
Recomenda-se que o app realize uma sincronização total com o servidor depois de receber essa chamada.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],null,["To receive simple downstream messages, each client app needs to implement the\nmethods on the\n[firebase::messaging::Listener](/docs/reference/cpp/class/firebase/messaging/listener)\nAPI.\n\nInitialize FCM\n\nBefore you can use FCM to get access to your registration token or receive messages it must be initialized.\n\nTo initialize FCM, call\n[::firebase::messaging::Initialize](/docs/reference/cpp/namespace/firebase/messaging#initialize)\nand supply it with your\n[::firebase::App](/docs/reference/cpp/class/firebase/app)\nobject as well as an implementation of the\n[::firebase::messaging::Listener](/docs/reference/cpp/class/firebase/messaging/listener)\nclass. \n\n```c++\nMyListener my_listener_implementation;\n::firebase::messaging::Initialize(app, &my_listener_implementation);\n```\n\nAccess the registration token\n\nOn initial startup of your app, the FCM SDK generates a registration\ntoken for the client app instance. If you want to target single devices, or\ncreate device groups for FCM, you'll need to access this token.\n\nYou can access the token's value through the\n[::firebase::messaging::Listener::OnTokenReceived](/docs/reference/cpp/class/firebase/messaging/listener#ontokenreceived)\nvirtual function. \n\n```c++\nvoid OnTokenReceived(const char* token) {\n LogMessage(\"The registration token is `%s`\", token);\n\n // TODO: If necessary send token to application server.\n}\n```\n\nReceive and handle messages\n\nTo receive messages, your Listener class must implement the\n[OnMessage](/docs/reference/cpp/class/firebase/messaging/listener#onmessage)\nvirtual function.\n\nOverride `OnMessage`\n\nBy overriding the method\n[::firebase::messaging::Listener::OnMessage](/docs/reference/cpp/class/firebase/messaging/listener#onmessage),\nyou can perform actions based on the received message and get the message data: \n\n```c++\nvoid OnMessage(const ::firebase::messaging::Message& message) {\n LogMessage(TAG, \"From: %s\", message.from.c_str());\n LogMessage(TAG, \"Message ID: %s\", message.message_id.c_str());\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 `Message::message_type` field.\n\nMessages Deleted\n\nSent to your app when the FCM server deletes pending messages.\n`Message::message_type` will be `\"deleted_messages\"`. Messages may be delete due\nto:\n\n1. Too many messages 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."]]