Firebase admin sdk ios notification custom sound problem

I send to my application with notification firebase admin sdk and I can receive the notification on the ios android side without any problems, but when the notification comes in ios, the notification comes without sound When I did research for this, I saw that I had to send the sound in Apns in this way and I sent it, but this does not work, there is no sound but the notification comes.

public async static Task SendNotification(string title, string body, string token, string type)
 {
     InitializeFirebaseApp();
     var message = new Message()
     {
         Notification = new Notification()
         {
             Title = title,
             Body = body,
         },

         Token = token,
         Data = new Dictionary<string, string>()
             {
               
                 {"type", type }
             },
         
         Apns = new ApnsConfig()
         {
             Aps = new Aps()
             {
                 Sound = "sound.wav",
             },
         },

     };
     // Bildirimi gönderme
     var messaging = FirebaseMessaging.DefaultInstance;
     try
     {
         // ...
         await messaging.SendAsync(message);

         // ...
     }
     catch (Exception ex)
     {
         // Using a using block ensures proper file 
         // Optionally, you can still log to the console for immediate visibility
         Console.WriteLine($"Error sending notification: {ex.Message}");
         WriteLog("Hata: " + ex.Message);

         // Optionally, you can return a specific response or continue with the execution
     }
     //await messaging.SendAsync(message);
 }

there is no problem with the sound file or location because when I send a notification with postman in this way, the notification comes with the sound

{
   "to" : "My device id",
   "notification" : {
       "title" : "Sound test",
       "body" : "Sound body",
       "sound" : "sound.wav"
   }
}

can you help me with this

Solution :

I moved Apns just below Notification and the problem was solved. I hope I can help a friend who encountered this problem

public async static Task SendNotification(string title, string body, string token, string type)
 {
     InitializeFirebaseApp();
     var message = new Message()
     {
         Notification = new Notification()
         {
             Title = title,
             Body = body,
         },

         Apns = new ApnsConfig()
         {
             Aps = new Aps()
             {
                 Sound = "sound.wav",
             },
         },

         Token = token,
         Data = new Dictionary<string, string>()
             {
               
                 {"type", type }
             },

     };

     // Bildirimi gönderme
     var messaging = FirebaseMessaging.DefaultInstance;
     try
     {
         // ...
         await messaging.SendAsync(message);

         // ...
     }
     catch (Exception ex)
     {
         // Using a using block ensures proper file 
         // Optionally, you can still log to the console for immediate visibility
         Console.WriteLine($"Error sending notification: {ex.Message}");
         WriteLog("Hata: " + ex.Message);

         // Optionally, you can return a specific response or continue with the execution
     }
     //await messaging.SendAsync(message);
 }

Leave a Comment