针对read_timeout的Firebase消息取消注册通知失败
我试图从一台设备向另一台设备发送通知,让用户知道有一条等待他的消息。
当我试图捕获并处理 RemoteMessage 时,控制台会打印出这样的内容。它发生在 iOS 物理设备上。
该功能以前运行良好,但现在无法通过设备、客户端向其他用户发送通知。
功能概述:
static Future<void> sendNotificationToOtherUser(
String title, String body, String token) async {
final headers = {
'content-type': 'application/json',
'Authorization':
'key={I hide KEY but I assure you there is nothing wrong with key}'
};
List<String> list = List();
// token is not null
list.add(token);
final postUrl = 'https://fcm.googleapis.com/fcm/send';
final data = {
"registration_ids": list,
"notification": {
"title": '$title',
"body": '$body',
},
};
final response = await http.post(Uri.parse(postUrl),
body: json.encode(data),
encoding: Encoding.getByName('utf-8'),
headers: headers);
if (response.statusCode == 200) {
// it prints 200 so works perfectly
print(response.body);
print('test ok push CFM');
return true;
} else {
print(response.body);
print(' CFM error');
// on failure do sth
return false;
}
}
似乎一切正常,但其他设备无法捕获通知并由于我在下面放置的错误而显示它。错误:
[connection] nw_endpoint_handler_set_adaptive_read_handler [C6.1 216.58.212.42:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] unregister notification for read_timeout failed
[connection] nw_endpoint_handler_set_adaptive_write_handler [C6.1 216.58.212.42:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] unregister notification for write_timeout failed
图书馆:
firebase_core: ^1.0.3
firebase_auth: ^1.0.2
cloud_firestore: ^1.0.4
firebase_storage: ^8.0.1
firebase_messaging: ^10.0.0
Flutter SDK 版本:
[?] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale
en-GB)
• Flutter version 2.2.2 at /Users/user/development/flutter
• Framework revision d79295af24 (4 weeks ago), 2021-06-11 08:56:01 -0700
• Engine revision 91c9fc8fe0
• Dart version 2.13.3