【发布时间】:2020-08-05 08:24:31
【问题描述】:
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-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
我的 pubspec.yaml 包:
firebase_messaging: ^5.1.6
我错过了什么吗? 谢谢。
【问题讨论】:
-
你用什么来发送通知?并接收它们?你在使用任何包吗?
-
我使用 firebase 云消息传递:firebase_core: ^0.4.0+9, firebase_analytics: ^5.0.2, firebase_auth: ^0.14.0+5; firebase_messaging:^5.1.6,
-
应用崩溃时您看到的消息是什么?
-
它说应用程序停止工作。你认为我可以在控制台中看到错误消息,在收到通知的手机上吗?当我进行测试时,只有发送通知的手机在 USB 中,所以我没有在另一边看到错误消息
-
尝试连接死机的手机,看看死机时的错误是什么。也许它与通知无关。
标签: flutter dart push-notification notifications firebase-cloud-messaging