הודעות בנושא ב-Flutter
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
הודעות בנושאים ב-FCM מבוססות על מודל פרסום/הרשמה, ומאפשרות לשלוח הודעה למספר מכשירים שהמשתמשים שלהם הצטרפו לנושא מסוים. אתם כותבים את ההודעות בנושא לפי הצורך, ו-FCM מטפל בניתוח ובשליחה של ההודעה באופן מהימן למכשירים הנכונים.
לדוגמה, משתמשים באפליקציה מקומית לחיזוי גאות ושפל יכולים להצטרף לנושא 'התראות על זרמי גאות ושפל' ולקבל התראות על תנאים אופטימליים לדיג במים מלוחים באזורים ספציפיים. משתמשים באפליקציית ספורט יכולים להירשם לעדכונים אוטומטיים של תוצאות משחקים בשידור חי של הקבוצות האהובות עליהם.
כמה דברים שכדאי לזכור לגבי נושאים:
הודעות בנושאים מתאימות במיוחד לתוכן כמו מזג אוויר או מידע אחר שזמין לכולם.
הודעות בנושאים עוברות אופטימיזציה לשיפור התפוקה ולא לקיצור זמן האחזור. כדי לשלוח הודעות במהירות ובאופן מאובטח למכשירים בודדים או לקבוצות קטנות של מכשירים, צריך לטרגט את ההודעות לטוקנים של רישום ולא לנושאים.
אם אתם צריכים לשלוח הודעות לכמה מכשירים לכל משתמש, כדאי לשקול שליחת הודעות לקבוצת מכשירים בתרחישי השימוש האלה.
הודעות בנושא תומכות במספר בלתי מוגבל של מינויים לכל נושא. עם זאת, ל-FCM יש מגבלות בתחומים הבאים:
- כל מופע של אפליקציה יכול להירשם לעד 2,000 נושאים.
- אם אתם משתמשים בייבוא באצווה כדי להירשם למופעי אפליקציות, כל בקשה מוגבלת ל-1,000 מופעי אפליקציות.
- התדירות של מינויים חדשים מוגבלת לפי קצב לכל פרויקט. אם שולחים יותר מדי בקשות להרשמה בפרק זמן קצר, שרתי FCM ישיבו עם תגובה מסוג
429 RESOURCE_EXHAUSTED
("חריגה מהמכסה"). צריך לנסות שוב עם השהיה מעריכית לפני ניסיון חוזר (exponential backoff).
הרשמה של אפליקציית הלקוח לנושא
אפליקציות לקוח יכולות להירשם לנושא קיים או ליצור נושא חדש. כשלקוח של אפליקציה נרשם לנושא חדש (שעדיין לא קיים בפרויקט Firebase), נוצר נושא חדש בשם הזה ב-FCM, וכל לקוח יכול להירשם אליו בהמשך.
כדי להירשם למינוי לנושא, מתקשרים אל subscribeToTopic()
ומציינים את שם הנושא. השיטה הזו מחזירה Future
, שמוחזר כשהמינוי מצליח:
await FirebaseMessaging.instance.subscribeToTopic("topic");
כדי לבטל את ההרשמה, מתקשרים למספר unsubscribeFromTopic()
ומציינים את שם הנושא.
אין תמיכה ב-subscribeToTopic()
וב-unsubscribeFromTopic()
בלקוחות אינטרנט. הוראות לניהול מינויים למשתמשי אינטרנט מפורטות במאמר שליחת הודעות לנושאים באינטרנט או ב-JavaScript.
השלבים הבאים
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-16 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-16 (שעון 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)."]]