当我使用ios模拟器发送通知时,我获得了所有设备令牌的所有成功响应。但是,当我使用模拟器发送通知时,我没有获得所有令牌的成功响应。
print("number of tokens ${getAllTokens.length}");
getAllTokens.forEach((dynamic i) async {
String url = "https://fcm.googleapis.com/fcm/send";
final msg = jsonEncode({
"to": i,
"notification": {
"body": "Alarm turn On",
"title": "FCM title",
"sound": "default",
"badge": "1"
},
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
},
});
Map<String, String> headers = {
'Content-Type': 'application/json',
'authorization':
'key=<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) {
print("%%%%%% ${responce.body}");
throw new Exception("Error while fetching data");
} else {
print("success");
}
});
});
使用仿真器测试结果:
flutter: number of tokens 16
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
flutter: success
使用仿真器测试结果:
I/flutter ( 5027): number of tokens 16
I/flutter ( 5027): success
I/chatty ( 5027): uid=10123(com.example.rigato) 1.ui identical 13 lines
I/flutter ( 5027): success
I/flutter ( 5027): success