flutter-push通知不应显示用户在聊天室中特别在iOS中的聊天室
推送通知是使用Flutter应用程序中的Firebase集成的。当我在同一个聊天室中,我会收到通知,就像我们在聊天室里时,我们不应该为该特定的聊天室收到任何类型的通知。我们可以为另一个用户挑战提供通知。它在Android中工作正常,但在iPhone上不正常。请建议建议叠加层的替代方法。
这是主要代码。 DART:
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true, badge: true, sound: true);
在聊天室中。
var androidInitilize =
new AndroidInitializationSettings('@mipmap/ic_launcher');
var iOSinitilize = new IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification
);
var initilizationsSettings = new InitializationSettings(
android: androidInitilize, iOS: iOSinitilize);
flutterLocalNotificationsPlugin.initialize(initilizationsSettings,
onSelectNotification: null);
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
RemoteNotification notification = message.notification;
AndroidNotification android = message.notification.android;
if (notification != null) {
if (android != null) {
String userChatID = message.data["userchatId"];
if (userChatID.toString() != activeCurrentUserChatID) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
Platform.isAndroid
? 'com.xyz
: 'com.xyz',
"xyz",
// one that already exists in example app.
icon: null,
),
));
// _showNotification(message.data["title"], message.data["body"]);
}
}
else {
String userChatID = message.data["userchatId"];
if (userChatID.toString() != activeCurrentUserChatID) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
iOS:IOSNotificationDetails(
presentAlert: true,
presentBadge: false,
presentSound: true,
badgeNumber: 0,
subtitle: "Hello",
)
));
}
}
}
});
预先感谢您。
Push notification is integrated using firebase in the flutter app. I am getting a notification when I am in the same chatroom, it should be like when we are in a chatroom we should not get any type of notification for that specific chatroom. We can have a notification for another userChatID. It is working fine in Android but not on iPhone. Please do suggest an alternative for overlay.
Here is a piece of code in the main. dart:
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true, badge: true, sound: true);
in ChatRoom.dart
var androidInitilize =
new AndroidInitializationSettings('@mipmap/ic_launcher');
var iOSinitilize = new IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification
);
var initilizationsSettings = new InitializationSettings(
android: androidInitilize, iOS: iOSinitilize);
flutterLocalNotificationsPlugin.initialize(initilizationsSettings,
onSelectNotification: null);
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
RemoteNotification notification = message.notification;
AndroidNotification android = message.notification.android;
if (notification != null) {
if (android != null) {
String userChatID = message.data["userchatId"];
if (userChatID.toString() != activeCurrentUserChatID) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
Platform.isAndroid
? 'com.xyz
: 'com.xyz',
"xyz",
// one that already exists in example app.
icon: null,
),
));
// _showNotification(message.data["title"], message.data["body"]);
}
}
else {
String userChatID = message.data["userchatId"];
if (userChatID.toString() != activeCurrentUserChatID) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
iOS:IOSNotificationDetails(
presentAlert: true,
presentBadge: false,
presentSound: true,
badgeNumber: 0,
subtitle: "Hello",
)
));
}
}
}
});
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
聊天室。不应该容纳通知听众。您应该将该功能移至一个主要小部件,无论页面如何,该功能都可以显示通知。要隐藏在某些页面上的通知,最好在状态下管理该通知,即将当前页面保存在应用程序状态,该页面可以在任何地方访问,并检查用户当前的EX中的哪个页面。
每当您导航到新页面时,请在状态中设置CurrentPage。
The Chatroom.dart shouldn't house the notifications listener. You should move that function to a main widget that can show notifications regardless of any page. To hide notifications on certain page it's a good idea to manage that in the state i.e. save the current page in an app state that can be access anywhere and check what page the user is currently in for ex.
and whenever you navigate to a new page set the currentPage in the state.