接收FCM通知点击事件
Receiver FCM notification click event
如何在flutter上接收通知点击事件?
我在 main.dart 上写了这段代码,但是 onMessage 处理事件不起作用。
此代码块也不适用于后台。
当在后台运行 onMessage 函数的应用程序无法处理时。
main.dart
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
void iOS_Permission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true)
);
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings)
{
print("Settings registered: $settings");
});
}
void firebaseCloudMessaging_Listeners(BuildContext context) {
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token){
print("Token : ${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 {
Navigator.pushNamed(context, "/");
print('on launch $message');
},
);
}
void main() {
print("uygulama Acildi");
debugPaintSizeEnabled = false;
runApp(MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],supportedLocales: [
const Locale('tr', 'TR'),
],
theme: ThemeData(fontFamily: 'Oswald'),
initialRoute: '/',
routes: <String, WidgetBuilder>{
// '/': (context) => SanalPulHareketleri(),
'/': (context) => SplashEkrani(),
'/kayit_ol': (context) => KayitOl(),
},
));
}
onMessage 当您收到通知且应用在前台 运行 时触发。
请查看 onResume 和 onLaunch 回调。
您可以找到更多信息 on the library page
如何在flutter上接收通知点击事件?
我在 main.dart 上写了这段代码,但是 onMessage 处理事件不起作用。
此代码块也不适用于后台。
当在后台运行 onMessage 函数的应用程序无法处理时。
main.dart
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
void iOS_Permission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true)
);
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings)
{
print("Settings registered: $settings");
});
}
void firebaseCloudMessaging_Listeners(BuildContext context) {
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token){
print("Token : ${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 {
Navigator.pushNamed(context, "/");
print('on launch $message');
},
);
}
void main() {
print("uygulama Acildi");
debugPaintSizeEnabled = false;
runApp(MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],supportedLocales: [
const Locale('tr', 'TR'),
],
theme: ThemeData(fontFamily: 'Oswald'),
initialRoute: '/',
routes: <String, WidgetBuilder>{
// '/': (context) => SanalPulHareketleri(),
'/': (context) => SplashEkrani(),
'/kayit_ol': (context) => KayitOl(),
},
));
}
onMessage 当您收到通知且应用在前台 运行 时触发。
请查看 onResume 和 onLaunch 回调。 您可以找到更多信息 on the library page