iOS Custom Notification Sound UNNotificationSound doesn t play when iPhone is locked

0 votes

My app uses remote notifications with a NotificationService Extension in which I edit the notification before displaying it. I would like to let the user upload a custom sound file which should be played instead of the default sound. For this I use an shared AppGroup, which the app and the extension have access to.

The uploaded sound files are stored in the "Library/Sounds" directory as follows (my code for testing, without much 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"))

This is working fine as long as the iPhone is not locked. But if the iPhone is locked, there is no vibration and no sound is played (also no default sound). But I don't know why - according to apples documentation UNNotificationSound looks in "Library/Sounds" of the app shared group container directories. If I store the file directly in the main bundle, it works.

Does anyone have any idea what could be causing this?


  •  
Nov 9, 2022 in Mobile Development by gaurav
• 23,260 points
994 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Mobile Development

0 votes
0 answers

Can't play video on iOS in Safari: NotAllowedError

When I click a play button on ...READ MORE

Nov 8, 2022 in Mobile Development by gaurav
• 23,260 points
1,397 views
0 votes
0 answers

Notification issue in iOS 15.3

The below function is triggered when notification ...READ MORE

Nov 9, 2022 in Mobile Development by gaurav
• 23,260 points
532 views
0 votes
0 answers

Xcode(version 13.3.1) doesn’t support iOS 15.6

I updated my iPhone to iOS 15.6 ...READ MORE

Nov 10, 2022 in Mobile Development by gaurav
• 23,260 points
654 views
0 votes
0 answers

What is the new URL schema for Here WeGo v4 on iOS/Android?

The URL schema for Here WeGo on ...READ MORE

Nov 10, 2022 in Mobile Development by gaurav
• 23,260 points
528 views
0 votes
0 answers

is there any working twitter integration for android and ios

I have tried so many codes for ...READ MORE

Nov 11, 2022 in Mobile Development by gaurav
• 23,260 points
344 views
0 votes
0 answers
0 votes
0 answers

iOS Custom Notification Sound (UNNotificationSound) doesn't play when iPhone is locked

I edit the notification before showing it ...READ MORE

Sep 22, 2022 in IOS by Soham
• 9,710 points
818 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
11,401 views
0 votes
1 answer

Detecting BLE beacons that are not ibeacons on IOS

You'll have to understand that CoreLocation is ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
875 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP