My app is downloading a .wav file and moving it to Library/Sounds, then scheduling a local notification via UNNotificationRequest
with that sound's file name. This request sends notifications as expected, but the custom sound I have added only plays aloud when the phone is unlocked, not when the notification is getting delivered to the phone's lock screen. However, if I use UNNotificationSound.default()
instead of my custom sound, the default push sound will play both on the lock screen and when the device is unlocked. Anyone have any ideas what could be causing this issue? My code is simple:
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)
EDIT: this isn't a problem for bundled sounds (dragged & dropped into Xcode), but I see the above issue only when I use sounds downloaded by my app and moved into Library/Sounds.