我用dart&flutter创建了一个应用,并使用了Firebase通知( Cloud Messaging),现在有时候可以,并且移动接收到即将来临的数据,但是有时无法正常工作,并且移动无法接收任何数据,有时当我关闭应用程序并重新打开它时,我看到该应用程序接收到了火力发电厂的数据>
在服务器端,我将节点js和客户端与dart和flutter一起使用
服务器正常,并且数据已发送到Firebase,问题在抖动和接收到的数据上
Node js代码
var fcm = new FCM(serverKey);
var message = {
to: registration_token,
collapse_key: 'MyKey',
notification: {
title: title,
body: body
},
data: {
result: result,
sendedData: sendedData
}
};
cm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!");
} else {
console.log("Successfully sent User FCM: ", response);
}
});
Dart和Flutter代码
void _receiveDriverDataListeners() {
if (Platform.isIOS) iOSPermission();
const IosNotificationSettings(sound: true, badge: true, alert: true);
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on resume $message');
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
},
);
}
void iOSPermission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
});
}