问题描述
我正在 BigSur 上构建菜单栏应用。应用程序经常发送 UserNotifications
。我想对显示的 .default
声音应用不同的声音用户通知。我在播放声音时遇到了一些麻烦。我已经尽我所能,但仍然无法让它发挥作用。
到目前为止我所做的(音频文件是 one.caf
)
- 检查多种音频格式 (
.mp3,.wav,.caf
) - 将位置从
project root
更改为controllers
目录
- 我已检查是否为文件选择了目标
- 我已经检查了该文件是否也在
finder
中的同一目录中。
我不确定这是否与我调用通知的方式有关,但我对此表示怀疑。无论哪种方式,这是我在需要显示通知时运行的代码。仅供参考,我正在使用 singleton
类来管理通知
private func showNotification(title: String,subtitle: String) {
let content = UNMutableNotificationContent()
content.title = title
content.subtitle = subtitle
// Getting asset name using URL
let stringPath = Bundle.main.url(forResource: "one",withExtension: "caf")
print(stringPath?.lastPathComponent)
// content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "one.caf"))
UNNotificationSound(named: UNNotificationSoundName(stringPath?.lastPathComponent ?? ""))
content.sound = .defaultCritical
let request = UNNotificationRequest(identifier: UUID().uuidString,content: content,trigger: nil)
UNUserNotificationCenter.current().add(request)
}
包装内的内容是
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)