پیامرسانی موضوع در فلاتر
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
بر اساس مدل انتشار/اشتراک، پیامرسانی موضوع FCM به شما امکان میدهد پیامی را به چندین دستگاهی که موضوع خاصی را انتخاب کردهاند ارسال کنید. شما پیامهای موضوعی را در صورت نیاز مینویسید، و FCM مسیریابی و تحویل پیام را بهطور قابل اعتماد به دستگاههای مناسب انجام میدهد.
برای مثال، کاربران یک برنامه محلی پیشبینی جزر و مد میتوانند موضوع «هشدار جریانهای جزر و مد» را انتخاب کنند و اعلانهای شرایط بهینه ماهیگیری در آبهای شور را در مناطق مشخص دریافت کنند. کاربران یک برنامه ورزشی می توانند مشترک به روزرسانی های خودکار در نمرات بازی های زنده برای تیم های مورد علاقه خود شوند.
نکاتی که باید در مورد موضوعات در نظر داشت:
پیامهای موضوعی برای محتوایی مانند آبوهوا یا سایر اطلاعات در دسترس عموم مناسبتر است.
پیامهای موضوعی بهجای تأخیر بهینهسازی شدهاند . برای تحویل سریع و ایمن به تک دستگاهها یا گروههای کوچکی از دستگاهها، پیامها را به نشانههای ثبتنام، نه موضوعات، هدف قرار دهید .
اگر نیاز به ارسال پیام به چندین دستگاه برای هر کاربر دارید، پیامهای گروهی دستگاه را برای آن موارد استفاده در نظر بگیرید.
پیامرسانی موضوع از اشتراکهای نامحدود برای هر موضوع پشتیبانی میکند. با این حال، FCM محدودیت هایی را در این زمینه ها اعمال می کند:
- یک نمونه برنامه را نمی توان در بیش از 2000 موضوع مشترک کرد.
- اگر از واردات دستهای برای اشتراک نمونههای برنامه استفاده میکنید، هر درخواست به 1000 نمونه برنامه محدود میشود.
- تعداد اشتراکهای جدید در هر پروژه با نرخ محدود است. اگر تعداد زیادی درخواست اشتراک را در مدت زمان کوتاهی ارسال کنید، سرورهای FCM با پاسخ
429 RESOURCE_EXHAUSTED
("بیش از سهمیه") پاسخ خواهند داد. با عقب نشینی نمایی دوباره امتحان کنید.
برنامه مشتری را در یک موضوع مشترک کنید
برنامه های مشتری می توانند در هر موضوع موجود مشترک شوند یا می توانند موضوع جدیدی ایجاد کنند. هنگامی که یک برنامه مشتری در نام موضوع جدیدی مشترک می شود (نامی که قبلاً برای پروژه Firebase شما وجود ندارد)، موضوع جدیدی با آن نام در FCM ایجاد می شود و هر مشتری می تواند متعاقباً در آن مشترک شود.
برای اشتراک در یک موضوع، subscribeToTopic()
با نام موضوع فراخوانی کنید. این روش یک Future
را برمیگرداند که پس از موفقیت در اشتراک حل میشود:
await FirebaseMessaging.instance.subscribeToTopic("topic");
برای لغو اشتراک، unsubscribeFromTopic()
با نام موضوع فراخوانی کنید.
subscribeToTopic()
و unsubscribeFromTopic()
برای مشتریان وب پشتیبانی نمی شوند. برای یادگیری نحوه مدیریت اشتراک برای کاربران وب، به ارسال پیام به موضوعات در وب/جاوا اسکریپت مراجعه کنید.
مراحل بعدی
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Topic messaging on Flutter\n\n\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-----------------------------------\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\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)."]]