Я использую Flutter для отправки push-уведомлений через Firebase Cloud Messaging (FCM) с использованием API HTTP v1. Уведомление работает нормально на Android, но при отправке на устройства iOS я получаю ошибку 400 (неверный запрос). Ниже приведен код, который я использую:
Я использую Flutter для отправки push-уведомлений через Firebase Cloud Messaging (FCM) с использованием API HTTP v1. Уведомление работает нормально на Android, но при отправке на устройства iOS я получаю ошибку 400 (неверный запрос). Ниже приведен код, который я использую: [code]Future\ sendNotificationF() async { try { String? accessToken = await CommonMethods.getAccessToken(); final \_dio = Dio();
if (token == null) { print("Error: Could not retrieve FCM token."); Fluttertoast.showToast( msg: "Error: Could not retrieve FCM token.", toastLength: Toast.LENGTH_LONG); return; }
var data = { "message": { "token": token, "data": { "title": "Hello", "message": "This is a notification message.", "body": "This is the body content.", "sound": "notification_chat", }, "notification": { "title": "Hello", "body": "This is the notification body.", }, "android": { "priority": "high", "notification": { "sound": "notification_chat", // Custom sound for Android "channel_id": "astrosane", }, }, "apns": { "payload": { "aps": { "sound": "notification_chat", // Custom sound for iOS }, }, }, } };
final response = await _dio.post( 'https://fcm.googleapis.com/v1/projects/project-ID/messages:send', data: jsonEncode(data), );