Friday, March 16, 2018

UNNotificationRequest plays custom sound only when iPhone is unlocked

Leave a Comment

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.

1 Answers

Answers 1

From here, you will notice that :

Waveform Audio File Format (WAVE, or more commonly known as WAV due to its filename extension - both pronounced "wave"[6])3[7][8][9] (rarely, Audio for Windows)[10] is a Microsoft and IBM audio file format standard for storing an audio bitstream on PCs.

I assume that Apple prefer native Apple sound format, like AIFF or CAF, which are both developped by Apple.

May you retry with an AIFF or or CAF sound file format and confirm use if the issue is still here ?

You may also take a look here .

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment