【发布时间】:2021-05-19 04:09:12
【问题描述】:
我已经有一段时间没有解决方案了。当应用程序在后台 onBackgroundMessage 未被调用时,我无法处理通知。有什么问题?
Future<dynamic> _myBackgroundMessageHandler
(Map<String, dynamic> message) async {
print("onBackground Message called");
return PushNotificationService().showNotification(message);
}
class PushNotificationService{
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
Future initialize(context) async{
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
fetchRideInfo(message['data']['orderId'], context, "onMessage");
},
onBackgroundMessage: Platform.isIOS ? null:_myBackgroundMessageHandler,
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
fetchRideInfo(message['data']['orderId'], context, "onResume");
},
);
}
Future showNotification(Map<String, dynamic> message) async {
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'channel id',
'channel name',
'channel desc',
importance: Importance.max,
priority: Priority.high,
);
var platformChannelSpecifics =
new NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0,
'new message arived',
'i want ${message['data']}',
platformChannelSpecifics,
payload: 'Default_Sound',
);
}
【问题讨论】:
-
在 Android 或 iOS 中?
-
只是安卓兄弟
标签: flutter dart firebase-cloud-messaging