9/10/1
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user