在 Xamarion IOS 本地通知中播放自定义声音

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

我正在尝试使用本地通知播放自定义 mp3 声音文件(10-25 秒)。我已将自定义声音文件放置在 iOS 项目文件夹中(与 Resources 同一级别),其中 BundleResource 作为 BuildAction。我还将声音文件放置在具有相同构建操作的资源文件夹中。看来两者都不起作用。

var content = new UNMutableNotificationContent
            {
                Title = title,
                //Subtitle = "Notification Subtitle",
                Body = body,
                Badge = 1,
                Sound = UNNotificationSound.GetSound("music.mp3"), //play custom sound
                UserInfo = NSDictionary.FromObjectAndKey(NSObject.FromObject(id), NSObject.FromObject(notificationKey))
            };

            var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(10, false);
            var requestID = "request_" + id;
            var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger);
            UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) =>
            {
                if (err != null)
                {
                    throw new Exception($"Failed to schedule notification: {err}");
                }
            });

有什么建议吗?

xamarin xamarin.forms xamarin.android xamarin.ios
2个回答
0
投票

代码工作正常,我的手机声音静音。


0
投票

请务必遵循官方文档

  • 支持的声音格式:
    aiff
    wav
    caf
  • 声音长度必须少于30秒
© www.soinside.com 2019 - 2024. All rights reserved.