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

0 votes

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?

Sep 22, 2022 in IOS by Soham
• 9,710 points
819 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 IOS

0 votes
1 answer

Xcode 12.4 “Unsupported OS version” after iPhone iOS update 14.7

This may only be a short-term fix, ...READ MORE

answered Sep 21, 2022 in IOS by Rahul
• 9,680 points
1,238 views
0 votes
1 answer

Is there a way to generate high resolution PNGs of iOS emoji?

The glyphs for the "Apple Color Emoji" ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
2,453 views
0 votes
1 answer

Is it possible to run .APK/Android apps on iPad/iPhone devices?

It is not possible to run Android ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
4,534 views
0 votes
1 answer

what font face of clock on lock screen of iPhone (iOS 9)?

San Francisco is the default font in ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
1,191 views
0 votes
1 answer

How is a rounded rect view with transparency done on iphone?

view.layer.cornerRadius = radius; The difficult technique is to ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
905 views
0 votes
1 answer

Is there a way to to check if a picture was taken on that iPhone?

Actually, the model and manufacturer information is ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
646 views
0 votes
0 answers

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

My app uses remote notifications with a ...READ MORE

Nov 9, 2022 in Mobile Development by gaurav
• 23,260 points
995 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