我正在尝试将通知从 Java Rest Api(使用 Firebase Admin sdk)发送到我的 Flutter 应用程序 似乎它需要设备令牌来发送通知,我找不到如何获取该令牌.我是 Flutter 和 android 的新手,可能缺少任何关键步骤.如果可以,请你帮助我.谢谢.
I am trying to send notification from Java Rest Api (using Firebase Admin sdk) to my Flutter application and it seems it requires device token to send notification and I cannot find how to get that token. I am new to Flutter and android and may be missing any of the crucial step. Please help me if you can. Thanks.
将这个添加到你的包的 pubspec.yaml 文件中:
Add this to your package's pubspec.yaml file:
dependencies:
firebase_messaging: ^6.0.16
您可以从命令行安装软件包:
You can install packages from the command line:
使用颤振:
$ flutter packages get
现在在你的 Dart 代码中,你可以使用:
Now in your Dart code, you can use:
import 'package:firebase_messaging/firebase_messaging.dart';
实施:
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
@override
void initState() {
super.initState();
firebaseCloudMessaging_Listeners();
}
void firebaseCloudMessaging_Listeners() {
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token){
print(token);
});
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
},
);
}
void iOS_Permission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true)
);
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings)
{
print("Settings registered: $settings");
});
}
有关详细信息,请参阅 这个链接
For more details step by information please refer this link
希望对你有帮助
这篇关于Flutter 中的 Firebase (FCM) 注册令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!