v1.3.6
flutter_fcm
Firebase Cloud Messaging (FCM) 的 Flutter 插件,一种跨平台消息传递解决方案,可让您可靠地在 Android 和 iOS 上发送消息。
41喜欢 310近 30 天下载140Pub 分数
AndroidiOSmacOS
Firebase 云消息传递(FCM)Flutter 包。
{"sdk":"flutter"}^16.1.0^4.3.0^19.5.0^5.1.1{"sdk":"flutter"}以下为英文项目原文快照,最新内容请访问 GitHub。
A Flutter plugin to use the Firebase Cloud Messaging API.
To learn more about Firebase Cloud Messaging, please visit the Firebase website
To get started with Firebase Cloud Messaging for Flutter, please see the documentation.
To get started with Firebase Cloud Messaging for Flutter, see Android Installation. and iOS Installation.
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);
}
}
}