Changed the Parameter DeviceToken to FcmToken
This commit is contained in:
parent
7f4f266dd0
commit
47a3d6035c
@ -4,6 +4,6 @@
|
||||
{
|
||||
public required string Username { get; set; }
|
||||
public required string Password { get; set; }
|
||||
public required string DeviceToken { get; set; }
|
||||
public required string FcmToken { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -52,35 +52,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var deviceToken = "ewjsd9zGTh6aS6Vg3Z_uxP:APA91bFZi1KzZdxlHUfBa_dX3PEJnDhX4R2dvFjD9Zf3WPSm957Hb53JPim7jrpjhpeOY61I9rfc11c3wpqWfW_06aSx-Yb8UfWpygV2YgZ8gbHtSku_PSQ";
|
||||
var message = new Message()
|
||||
{
|
||||
Token = deviceToken,
|
||||
Notification = new Notification
|
||||
{
|
||||
Title = "Hello from .NET",
|
||||
Body = "This is a test message"
|
||||
}
|
||||
};
|
||||
try
|
||||
{
|
||||
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
|
||||
_logger.LogInfo("Successfully sent message: {MessageId}", response);
|
||||
}
|
||||
catch (FirebaseMessagingException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error sending push notification.");
|
||||
|
||||
// Check for the specific error codes that indicate an invalid token
|
||||
if (ex.MessagingErrorCode == MessagingErrorCode.Unregistered ||
|
||||
ex.MessagingErrorCode == MessagingErrorCode.InvalidArgument)
|
||||
{
|
||||
_logger.LogWarning("FCM token is invalid and should be deleted: {Token}", deviceToken);
|
||||
|
||||
// Add your logic here to remove the invalid token from your database
|
||||
// await YourTokenService.DeleteTokenAsync(recordAttendanceDot.DeviceToken);
|
||||
}
|
||||
}
|
||||
|
||||
var user = await _context.ApplicationUsers
|
||||
.FirstOrDefaultAsync(u => u.Email == loginDto.Username || u.PhoneNumber == loginDto.Username);
|
||||
@ -258,7 +229,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
// It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
|
||||
var message = new Message()
|
||||
{
|
||||
Token = loginDto.DeviceToken,
|
||||
Token = loginDto.FcmToken,
|
||||
Notification = new Notification
|
||||
{
|
||||
Title = "Hello from AuthController",
|
||||
@ -281,7 +252,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
if (ex.MessagingErrorCode == MessagingErrorCode.Unregistered ||
|
||||
ex.MessagingErrorCode == MessagingErrorCode.InvalidArgument)
|
||||
{
|
||||
_logger.LogWarning("FCM token is invalid and should be deleted from the database: {Token}", loginDto.DeviceToken ?? string.Empty);
|
||||
_logger.LogWarning("FCM token is invalid and should be deleted from the database: {Token}", loginDto.FcmToken ?? string.Empty);
|
||||
|
||||
// TODO: Implement the logic here to remove the invalid token from your database.
|
||||
// Example: await YourTokenService.DeleteTokenAsync(loginDto.DeviceToken);
|
||||
|
Loading…
x
Reference in New Issue
Block a user