This commit is contained in:
Hamza-Ayed
2024-09-10 03:10:04 +03:00
parent 3135187408
commit 6aeb091719
15 changed files with 419 additions and 284 deletions

View File

@@ -610,13 +610,27 @@ class FirebaseMessagesController extends GetxController {
);
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Notification sent successfully.');
print('Response body: ${response.body}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
// Parse the response body to handle specific errors like 'UNREGISTERED'
final responseBody = jsonDecode(response.body);
if (responseBody['error'] != null &&
responseBody['error']['status'] == 'NOT_FOUND' &&
responseBody['error']['details'] != null) {
for (var detail in responseBody['error']['details']) {
if (detail['errorCode'] == 'UNREGISTERED') {
print(
'FCM token is unregistered or invalid. Consider removing this token.');
// Remove the unregistered token from your database here.
// Example: removeTokenFromDatabase(token);
}
}
}
}
} catch (e) {
print('Error sending notification: $e');
@@ -721,15 +735,27 @@ class FirebaseMessagesController extends GetxController {
},
}),
);
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Notification sent successfully.');
print('Response body: ${response.body}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
// Parse the response body to handle specific errors like 'UNREGISTERED'
final responseBody = jsonDecode(response.body);
if (responseBody['error'] != null &&
responseBody['error']['status'] == 'NOT_FOUND' &&
responseBody['error']['details'] != null) {
for (var detail in responseBody['error']['details']) {
if (detail['errorCode'] == 'UNREGISTERED') {
print(
'FCM token is unregistered or invalid. Consider removing this token.');
// Remove the unregistered token from your database if needed
}
}
}
}
} catch (e) {
print('Error sending notification: $e');
@@ -785,10 +811,26 @@ class FirebaseMessagesController extends GetxController {
);
if (response.statusCode == 200) {
// Notification sent successfully
print('Notification sent successfully.');
print('Response body: ${response.body}');
} else {
// Handle error response
'Failed to send notification. Status code: ${response.statusCode}';
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
// Parse the response body to handle specific errors like 'UNREGISTERED'
final responseBody = jsonDecode(response.body);
if (responseBody['error'] != null &&
responseBody['error']['status'] == 'NOT_FOUND' &&
responseBody['error']['details'] != null) {
for (var detail in responseBody['error']['details']) {
if (detail['errorCode'] == 'UNREGISTERED') {
print(
'FCM token is unregistered or invalid. Consider removing this token.');
// Remove the unregistered token from your database if needed
}
}
}
}
} catch (e) {
// Handle other exceptions