TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

Fix/Ios notifications not playing sound #352

Closed SgtMadmonkey closed 1 week ago

SgtMadmonkey commented 1 month ago

Notifications sounds are not being played on iOS while the app is in the foreground.

This issue was addressed in #295 , with the solution being a workaround by manually playing a sound.

Upon further investigation, I have determined the issue to be a missing flag on the WillPresentNotification completion handler. This plays the sound defined within the notification payload's ApnsConfig object (see https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsconfig).

For example, setting the following in your notification will play the user-defined default alert sound (iOS 17.2+):

"message": {
  ...
  "apns": {
    "payload": {
      "aps": {
        "sound" : "default"
      }
    }
  }
}

Additionally, I have included changes to support the UNNotificationPresentationOptions of Banner and List, introduced in iOS 14 (deprecating UNNotificationPresentationOptions.Alert).

Apologies if I did anything incorrect, this is my first public pull request and I was failing to install the legacy net 6.0 workloads to test, however I have custom implemented the WillPresentNotification delegate in my personal projects and is working as intended.

AdamEssenmacher commented 1 month ago

Thanks for the PR! I'll take a look.

SgtMadmonkey commented 1 month ago

Apologies, seems I did miss something. Accidentally removed the isSilentInForeground check - have amended