iOS 10 UserNotifications custom sound in background mode

Found out that alertSound doesn't have the correct file path hence the content.sound sets nothing. I was saving the recorded file in documents directory and the file path retrieve for real device is different as compared to the simulator.

Setting a sound file which is placed in project bundle did the trick

content.sound = UNNotificationSound(named: "out.caf")

In Swift 4.2 and Xcode 10.1

For local notifications to play sound

let content = UNMutableNotificationContent()
content.title = "Notification Tutorial"
content.subtitle = "from ioscreator.com"
content.body = " Notification triggered"
//Default sound
content.sound = UNNotificationSound.default
//Play custom sound
content.sound = UNNotificationSound.init(named:UNNotificationSoundName(rawValue: "123.mp3"))