-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No notification sound when IOS app is open #295
Comments
I am able to fix the notification sound when app is open using the following code. void NotificationReceived(object source, FCMNotificationReceivedEventArgs e)
|
I am able to fix the notification sound when app is open in IOS |
I ran into this issue while working on one of my projects, and managed to find the fix for it. The issue stems from a missing flag in the iOS A temporary workaround for this can be made by manually overriding the public class FirebaseDelegate : NSObject, IUNUserNotificationCenterDelegate
{
private static FirebaseDelegate instance = null;
public static FirebaseDelegate Instance
{
get => instance ??= new();
}
FirebaseDelegate(){}
public void Initialize()
{
UNUserNotificationCenter.Current.Delegate = this;
}
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
var fcmNotification = notification.ToFCMNotification();
((FirebaseCloudMessagingImplementation)CrossFirebaseCloudMessaging.Current).OnNotificationReceived(fcmNotification);
if (!fcmNotification.IsSilentInForeground)
{
if (OperatingSystem.IsIOSVersionAtLeast(14))
{
completionHandler(UNNotificationPresentationOptions.Banner
| UNNotificationPresentationOptions.List
| UNNotificationPresentationOptions.Sound);
}
else
{
completionHandler( UNNotificationPresentationOptions.Alert
| UNNotificationPresentationOptions.Sound);
}
}
}
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
{
((FirebaseCloudMessagingImplementation)CrossFirebaseCloudMessaging.Current).DidReceiveNotificationResponse(center, response, completionHandler);
}
} And then implement it after your Plugin.Firebase implementation in your MauiProgram.cs FirebaseCloudMessagingImplementation.Initialize();
FirebaseDelegate.Instance.Initialize(); Do note that the payload needs to contain the
I will submit a pull request with the proposed fix |
I have a .NET MAUI 8 App. There is sound with notification when app is close and in background.
Notification is visible but no sound when app is running in IOS. I am testing with my mobile, IOS version is 16.6.1
Following is the code to send the message from web.
Dim notificationMessage As Message
If isAndroid Then
notificationMessage = New Message With {
.Token = deviceToken
}
Else
notificationMessage = New Message With {
.Token = deviceToken,
.Apns = New ApnsConfig With {
.Aps = New Aps With {
.Sound = "Default"
}
}
}
End If
The text was updated successfully, but these errors were encountered: