电话接收者可以很好地接收json中的通知,并且在“ onMessage”中有带有json内容的打印件。但是,屏幕上没有显示通知。这是发送的json代码:
var client = http.Client();
var jsonData = json.encode({
"to": "/topics/$userId",
"notification": {
"body": "$notificationText",
"title": "Title",
},
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"sound": "default",
"status": "done",
"screen": "ListPostsScreen",
},
"content_available": true,
"priority": "high",
});
var headers = {
'Authorization': "key=$key",
'Content-Type': 'application/json',
};
var response = await client.post(url, headers: headers, body: jsonData);
print(response.body);
主屏幕中的firebaseMessaging:
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
这是main / AndroidManifest.xml中的intent过滤器
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
我的pubspec.yaml软件包:
firebase_messaging: ^5.1.6
我错过了什么吗? 谢谢。
答案 0 :(得分:2)
这有点愚蠢,但是我遇到了同样的问题,并且意识到我的请勿打扰已打开。但是我什么也没想到,因为我已将其关闭。
但是,我想是因为它按计划执行,所以仍在阻止通知。现在,在键入此内容时,我可以让它们正常工作-在 iOS 13.5 上显示在后台。
https://fireship.io/lessons/flutter-push-notifications-fcm-guide/
https://pub.dev/packages/firebase_messaging
https://github.com/fireship-io/192-flutter-fcm-push-notifications/blob/master/lib/main.dart