0

I'm creating a UNNotificationRequest with a UNNotificationSound as:

content.sound = UNNotificationSound(named: "alarmSounds/alarmAscending.caf")

The sound is in the folder (blue) alarmSounds in the main project folder.

The sound used is always the default sound instead of mine. I also tried it without the "alarmSound/" in the "named:" parameter but still not working.

Is there something special I need to do with the sound files?

This is using xcode 9 and trying it on an iOS 11 device.

zkon
  • 568
  • 1
  • 6
  • 19

1 Answers1

2

Make sure the sound file must be contained in the app’s bundle or in the Library/Sounds folder of the app's data container. If files exist in both locations then the file in the app's data container will be preferred.

To confirm/correct this...

Right click the file in the "Project Navigator", select "Show File Inspector" and make sure the file has a check mark next to your project in the "Target Membership" area.

Nishant Bhindi
  • 2,242
  • 8
  • 21
  • There is no "Target Membership" area in the inspector pane for these files. How do I fix this? – zkon Oct 09 '17 at 10:52
  • I selected the folder and it has the Target Membership section and I checked the project there. I then had to make sure that the sound reference included the folder name: "alarmSounds/alarmAscending.caf" and now it works. Thanks for your help, it is very much appreciated. – zkon Oct 09 '17 at 11:00