我正在使用fcm api进行推送通知,但是当应用程序处于前台时无法接收,当应用程序处于后台时它仍在工作,并且通知在移动设备中以静默方式出现,没有像其他应用程序那样在移动屏幕上弹出。 / p>
getAllTokens.forEach((dynamic i) async {
String url = "https://fcm.googleapis.com/fcm/send";
final msg = jsonEncode({
"to": i,
"notification": {
"body": "FCM test",
"title": "FCM test",
"sound": "default",
"badge": "1"
},
});
Map<String, String> headers = {
'Content-Type': 'application/json',
'authorization':
'key=<my_server_key>'
};
return await http
.post(url, body: msg, headers: headers)
.then((http.Response responce) {
final int statusCode = responce.statusCode;
if (statusCode < 200 || statusCode > 400 || json == null) {
throw new Exception("Error while fetching data");
} else {
print("success");
}
});
});