【发布时间】:2021-06-29 10:19:22
【问题描述】:
我有这个问题...发送通知时,在收听 onMessage 时的回调没有被调用,而通知显示在设备上。
初始化时
FirebaseMessaging.instance.requestPermission(
sound: true,
badge: true,
alert: true,
provisional: false,
);
String? token = await _firebaseMessaging.getToken();
FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
在听
FirebaseMessaging.onMessage.handleError((error) {
print("Erorrrrrr : ${error.toString()}");
}).listen((event) {
print(event.data);
_showNotification({
"title": event.notification?.title ?? "",
"body": event.notification?.body ?? "",
});
});
发布规范:
sdk: ">=2.12.0
firebase_core:^1.0.0
firebase_messaging:^9.0.0
医生总结
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 2.1.0-13.0.pre.214, on macOS 11.2.3 20D91 darwin-x64, locale en-EG)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] Connected device
【问题讨论】:
-
嗨!您尝试在前台而不是在后台处理传入消息,对吗?
-
在任何一种情况下,即使是 onMessageOpenedApp,也不会打印任何内容
-
我在 ^9.1.3 版本中遇到了同样的问题,我需要管理通知点击事件,但前台点击消息不起作用。到达 msg ai 在控制台中得到这个:“访问隐藏方法 Landroid/os/WorkSource;->add(I)Z (greylist,test-api,reflection, allowed)”,并且 FirebaseMessaging.onMessage.listen 没有被触发,我的 onmessage 函数只有一个 print(¨msg¨)
标签: flutter push-notification firebase-notifications