我的应用程序正在下载一个.wav文件并将其移动到Library/Sounds,然后通过UNNotificationRequest调度一个带有该声音的文件名的本地通知。此请求按预期发送通知,但我添加的自定义声音只在手机解锁时播放,而不是在通知被发送到手机的锁定屏幕时播放。但是,如果我使用UNNotificationSound.default()而不是我的自定义声音,默认的推送声音将同时在锁定屏幕和设备解锁时播放。有人知道是什么导致了这个问题吗?我的代码很简单:
let soundName = "demoSound.wav" // (or nil to use default)
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests()
let content = UNMutableNotificationContent()
content.title = "Title"
content.body = "Body";
content.sound = soundName.flatMap { UNNotificationSound(named: $0) } ?? UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let identifier = "PushNotifierLocalNotification"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
center.add(request, withCompletionHandler: nil)编辑:这不是绑定声音的问题(拖放到Xcode中),但只有使用应用程序下载的声音并迁移到库/声音时,我才会看到上面的问题。
https://stackoverflow.com/questions/49020597
复制相似问题