搜尋套件、儲存庫與 APP 分類

套件詳情v1.3.6

flutter_fcm

Firebase Cloud Messaging (FCM) 的 Flutter 插件,一種跨平台訊息傳遞解決方案,可讓您可靠地在 Android 和 iOS 上傳送訊息。

AndroidiOSmacOS
近 30 天下載
177
喜歡數
41
Pub 分數
140

安裝套件

flutter pub add flutter_fcm

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flutter FCM 是一個 Flutter 插件,可使用 Firebase Cloud Messaging (FCM) 在 Android、iOS 和 macOS 上實現跨平台推播通知。它允許開發者可靠地將訊息(包括通知和資料負載)傳送至使用者裝置。該插件透過提供簡單直覺的 API 來處理權杖管理、訊息接收與背景處理,簡化了與 FCM 的整合。支援前景與背景訊息傳遞,非常適合即時應用更新與使用者互動。專為 Firebase 設計,易於使用,可簡化跨平台推播通知的設定與管理。

適用情境

  • 發送即時通知
  • 透過推播通知提升使用者參與度
  • 背景訊息處理
  • 應用狀態同步
  • 遠端設定更新

主要特色

  • 跨平台支援(Android、iOS、macOS)
  • 令牌管理工具
  • 前景和背景訊息處理
  • 用於訊息接收的簡單 API
  • 與 Firebase 控制台整合

適合對象

  • 需要推播通知的應用
  • 即時訊息功能
  • 整合 Firebase 的專案
  • 面向多個平台的移動應用
  • 用戶參與活動

使用建議

  • 需要 Firebase 項目設定
  • 每個平台都需要適當的權限
  • iOS 上的背景執行限制
  • 取決於 FCM 伺服器的可用性
  • 某些平台上的通知顯示需要手動處理

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Firebase Messaging Plugin for Flutter

A Flutter plugin to use the Firebase Cloud Messaging API.

To learn more about Firebase Cloud Messaging, please visit the Firebase website

Getting Started

To get started with Firebase Cloud Messaging for Flutter, please see the documentation.

Why flutter_fcm?

  • 🚀 Easy to use
  • ❤ Supports local notification
  • 🛡️ Null safety
  • ⚡ On notification Received/Pressed works in all states: foreground,background and even when app is closed(not running)

Getting Started

To get started with Firebase Cloud Messaging for Flutter, see Android Installation. and iOS Installation.

Usage

The easiest way to use this library is via the top-level functions.


import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_fcm/flutter_fcm.dart';

class Messaging {
  static String? token;

  static deleteToken() {
    Messaging.token = null;
    FCM.deleteRefreshToken();
  }
  static subscribeToTopic(String topic) {
    FCM.subscribeToTopic(topic);
  }
  static unsubscribeFromTopic(String topic) {
    FCM.unsubscribeFromTopic(topic);
  }

  @pragma('vm:entry-point')
  static Future<void> onNotificationReceived(RemoteMessage message) async {
    await Firebase.initializeApp();
    //print('Handling a message ${message}');

  }

  @pragma('vm:entry-point')
  static initFCM() async {
    try {
      await Firebase.initializeApp(
          options: DefaultFirebaseOptions.currentPlatform
      );
      await FCM.initializeFCM(
        withLocalNotification: true,
        // navigatorKey: Keys.navigatorKey,
        onNotificationReceived: onNotificationReceived,
        onNotificationPressed: (Map<String, dynamic> data) {

        },
        onTokenChanged: (String? token) {
          if (token != null) {
            //print('FCM token  $token');
            Messaging.token = token;


          }
        },
        // TODO add this icon to android/app/src/main/res/drawable/ic_launcher.png
        icon: 'ic_launcher',
      );
    } catch (e) {
      print(e);
    }
  }
}

所屬分類

依賴

原始碼儲存庫

使用此套件的專案

暫無相關資料。