我试图像这样在我的flutter应用程序中获取消息数据:
firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, alert: true, badge: true));
firebaseMessaging.configure(onLaunch: (Map<String, dynamic> message) {
print(" onLaunch called!" + message.toString());
}, onMessage: (Map<String, dynamic> message) {
print(" onMessage called!" + message.toString());
}, onResume: (Map<String, dynamic> message) {
print(" onResume called!" + message.toString());
});
firebaseMessaging.onIosSettingsRegistered.listen((iosNotificationSettings) {
print("============ IOS settings registered!");
});
设备正在接收通知,但我无法访问该通知。 通知json:
{
"notification": {
"body": "body",
"title": "title",
"sound": "default"
},
"priority": "high",
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
"registration_ids": ["a token"]
}
每当我收到通知时,都会在控制台中收到此消息:
W/FirebaseMessaging(22018): Error while parsing timestamp in GCM event
W/FirebaseMessaging(22018): java.lang.NumberFormatException: null
W/FirebaseMessaging(22018): at java.lang.Integer.parseInt(Integer.java:483)
W/FirebaseMessaging(22018): at java.lang.Integer.parseInt(Integer.java:556)
W/FirebaseMessaging(22018): at com.google.firebase.messaging.zzb.zzc(Unknown Source)
W/FirebaseMessaging(22018): at com.google.firebase.messaging.zzb.zze(Unknown Source)
W/FirebaseMessaging(22018): at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source)
W/FirebaseMessaging(22018): at com.google.firebase.iid.zzc.run(Unknown Source)
W/FirebaseMessaging(22018): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/FirebaseMessaging(22018): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/FirebaseMessaging(22018): at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source)
W/FirebaseMessaging(22018): at java.lang.Thread.run(Thread.java:762)
我如何获取消息以及随该通知发送的数据?
答案 0 :(得分:1)
print(message['body']);
尝试打印这样的消息并查看。
答案 1 :(得分:0)
尝试消息['title']。toString() message ['body']。toString()