Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Basato sul modello di pubblicazione/sottoscrizione, il servizio di messaggistica per argomenti FCM ti consente di inviare un messaggio
a più dispositivi che hanno attivato un determinato argomento. Componi i messaggi dell'argomento in base alle tue esigenze e FCM gestisce il routing e la consegna del messaggio in modo affidabile ai dispositivi giusti.
Ad esempio, gli utenti di un'app locale di previsione delle maree potrebbero attivare l'argomento "Avvisi sulle correnti di marea" e ricevere notifiche sulle condizioni ottimali per la pesca in acqua salata in aree specifiche. Gli utenti di un'app di sport
potrebbero abbonarsi agli aggiornamenti automatici sui risultati in tempo reale delle partite delle loro squadre
preferite.
Alcuni aspetti da tenere a mente sugli argomenti:
La messaggistica per argomenti è più adatta a contenuti come il meteo o altre informazioni disponibili pubblicamente.
I messaggi dell'argomento sono ottimizzati per la velocità effettiva anziché per la latenza. Per una distribuzione rapida e sicura a singoli dispositivi o piccoli gruppi di dispositivi, imposta come target dei messaggi i token di registrazione, non gli argomenti.
La messaggistica per argomento supporta un numero illimitato di sottoscrizioni per ogni argomento. Tuttavia, FCM
applica limiti in queste aree:
Un'istanza dell'app può essere iscritta a un massimo di 2000 argomenti.
Se utilizzi l'importazione batch per abbonarti alle istanze dell'app, ogni richiesta è limitata a 1000 istanze dell'app.
La frequenza dei nuovi abbonamenti è limitata in base alla velocità per progetto. Se invii
troppe richieste di iscrizione in un breve periodo di tempo, i server FCM
risponderanno con una risposta 429 RESOURCE_EXHAUSTED ("quota superata"). Esegui un nuovo tentativo
con il backoff esponenziale.
Abbonarsi a un argomento nell'app client
Le app client possono iscriversi a qualsiasi argomento esistente o crearne uno nuovo. Quando un'app client si iscrive a un nuovo nome di argomento (uno che non esiste già per il tuo progetto Firebase), viene creato un nuovo argomento con quel nome in FCM e qualsiasi client può successivamente iscriversi.
Per abbonarti a un argomento, chiama il numero subscribeToTopic() e comunica il nome dell'argomento. Questo metodo
restituisce un Future, che viene risolto quando l'abbonamento è andato a buon fine:
Per annullare l'iscrizione, chiama il numero unsubscribeFromTopic() e comunica il nome dell'argomento.
subscribeToTopic() e unsubscribeFromTopic() non sono supportati per i client web. Per scoprire come gestire gli abbonamenti per gli utenti web, consulta
Inviare messaggi agli argomenti su Web/JavaScript.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 UTC."],[],[],null,["\u003cbr /\u003e\n\nBased on the publish/subscribe model, FCM topic messaging allows you to send a message\nto multiple devices that have opted in to a particular topic. You compose topic messages as\nneeded, and FCM handles routing and delivering the message reliably to the right\ndevices.\n\nFor example, users of a local tide\nforecasting app could opt in to a \"tidal currents alerts\" topic and receive\nnotifications of optimal saltwater fishing conditions in specified areas. Users of a sports app\ncould subscribe to automatic updates in live game scores for their favorite\nteams.\n\nSome things to keep in mind about topics:\n\n- Topic messaging is best suited for content such as weather, or other publicly\n available information.\n\n- Topic messages are **optimized for throughput rather than latency** . For fast,\n secure delivery to single devices or small groups of devices,\n [target messages to registration tokens](/docs/cloud-messaging/send-message#send_messages_to_specific_devices),\n not topics.\n\n- If you need to send messages to multiple devices *per user* , consider\n [device group messaging](/docs/cloud-messaging/send-message#send_messages_to_device_groups)\n for those use cases.\n\n- Topic messaging supports unlimited subscriptions for each topic. However, FCM\n enforces limits in these areas:\n\n - One app instance can be subscribed to no more than 2000 topics.\n - If you are using [batch import](https://developers.google.com/instance-id/reference/server#manage_relationship_maps_for_multiple_app_instances) to subscribe app instances, each request is limited to 1000 app instances.\n - The frequency of new subscriptions is rate-limited per project. If you send too many subscription requests in a short period of time, FCM servers will respond with a `429 RESOURCE_EXHAUSTED` (\"quota exceeded\") response. Retry with exponential backoff.\n\nSubscribe the client app to a topic\n\nClient apps can subscribe to any existing topic, or they can create a new\ntopic. When a client app subscribes to a new topic name (one that does\nnot already exist for your Firebase project), a new topic of that name is\ncreated in FCM and any client can subsequently subscribe to it.\n\nTo subscribe to a topic, call `subscribeToTopic()` with the topic name. This method\nreturns a `Future`, which resolves when the subscription succeeded: \n\n await FirebaseMessaging.instance.subscribeToTopic(\"topic\");\n\nTo unsubscribe, call `unsubscribeFromTopic()` with the topic name.\n\n`subscribeToTopic()` and `unsubscribeFromTopic()` are not supported for web\nclients. To learn how to manage subscriptions for web users, see\n[Send messages to topics on Web/JavaScript](https://firebase.google.com/docs/cloud-messaging/js/topic-messaging).\n\nNext steps\n\n- Learn how to [send topic messages](/docs/cloud-messaging/send-message#send-messages-to-topics).\n- Learn how to [Manage topic subscriptions on the server](/docs/cloud-messaging/manage-topics)."]]