.Net Maui 7 iOS 推送通知声音不起作用

问题描述 投票:0回答:1

我正在使用 Azure 通知中心实施推送通知。到目前为止,只要通知按预期出现,它就可以正常工作,但没有声音(是的,我检查过以确保我的手机没有处于静音状态;)。

我的代码:

通知 json: {“aps”:{“alert”:“通知中心测试通知”},“声音”:“默认”}

AppDelegate.cs:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        // Other initialization code here...
        
        UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (approved, err) => {
            // Handle approval
            if (approved)
            {
            }
        });
        UIApplication.SharedApplication.RegisterForRemoteNotifications();
        // Watch for notifications while the app is active
        UNUserNotificationCenter.Current.Delegate = new NotificationDelegate();

        return base.FinishedLaunching(app, options);
    }

NotificationDelegate.cs:

    public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
    {
        if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
        {
            completionHandler(UNNotificationPresentationOptions.List | UNNotificationPresentationOptions.Banner | UNNotificationPresentationOptions.Sound);
        }
        else
            completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound);
    }

还有什么遗漏吗?

apple-push-notifications maui azure-notificationhub
1个回答
0
投票

您可以尝试在AppDelegate.cs中注册

RegisterUserNotificationSettings

var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null);

UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.