I edit the notification before showing it in my app's use of remote notifications with a NotificationService Extension. I want to allow users to submit their own sound files that should be played in place of the system default. I employ a common AppGroup for this purpose, to which both the app and the extension have access.
The "Library/Sounds" directory houses the uploaded sound files in the manner described below (my test code, with minimal error handling):
.....
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.xxx.xxx")
let soundsURL = containerURL!.appendingPathComponent("Library/Sounds/", isDirectory: true)
if !FileManager.default.fileExists(atPath: soundsURL.path) {
try! FileManager.default.createDirectory(atPath: soundsURL.path, withIntermediateDirectories: true)
}
if FileManager.default.fileExists(atPath: soundsURL.path) {
do {
try FileManager.default.copyItem(at: sourceURL, to: soundsURL.appendingPathComponent(sourceURL.lastPathComponent))
} catch {
// Exception
}
}
In the Notification Extension I change the sound of the notification to the name of the uploaded file:
bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "test.wav"))
As long as the iPhone is not locked, this is operating as intended. The iPhone does not vibrate and plays no sound when it is locked, though (also no default sound). However, according to Apple's documentation, I'm not sure why. In the shared group container folders of the programme, UNNotificationSound searches in "Library/Sounds." It functions if I store the file right in the main bundle.
Does anyone know what might be the cause of this?