UNNotificationSound not playing custom sound

I can't seem to get custom sounds to play on iOS 10, even though the same sounds played on iOS 9 using the old APIs

UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.body = ...
content.categoryIdentifier = ...
content.userInfo = ...
content.badge = ...
UNNotificationSound *bell = [UNNotificationSound soundNamed:soundName];
content.sound = bell;
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:[date timeIntervalSinceNow] repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString] content:content trigger:trigger];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
    NSLog(@"error scheduling %@", error);
}];


I haven't seen an reference to there being an issue in the release notes. Anyone else having this issue?

Accepted Reply

UNNotificationSound is available on watchOS, but the soundNamed: method is iOS-only: https://developer.apple.com/reference/usernotifications/unnotificationsound/1649031-soundnamed?language=objc So on watchOS, defaultSound is the only option.

Replies

Bueller, Bueller, Bueller...



Seriously, anyone not able to get a custom notification sound to work?

I think this is a bug of iOS itself. I've suffered exactly same problem with you. Reboot iOS Device, Uninstall the app, Reinstall through Xcode resolved my issue temporarily. However, this problem was occurred somehow later.

Everything works fine for me with iOS 10 unless I am installing over the app with Test flight. On a fresh install I have no issue, or with ios 9.

I can't get custom sounds to work either. Xcode 8 beta 5.


Does your sound name include the filename suffix?

Seeing the same issue here: custom sound not working in local notification under iOS 10, up to and including beta 5. Deleting the app and running it from Xcode briefly got it to work, but now it's gone again. Same problem using the old UILocalNotification method or the new UNNotificationRequest. Very worrisome.

At least you've seemed to get farther ... I can't get Xcode (beta 5) to even recognize "[UNNotificationSound soundNamed: ...]" It's like the method somehow isn't finished. The default sound seems to work just fine. Target is a watch app extension so maybe the behavior is different for the phone?


Oddly, I was able to get a notification to post in the simulator (even though I hadn't yet coded the proper request for authorization.) After one, however, it seemed to need the authorization for both the alert as well as the sound part. Not 100% sure because I also was using a static identifier.

We are seeing a similar issue as well. How can this go unsolved for so long? With possibly a single beta remaining before GM build, this is very worrying. I really hope we don't have an iOS 7.0->7.0.1->7.0.2->7.0.3 situation, where only after many patches the system was somewhat stable and without some really obvious bugs that should been fixed by beta 3.

Same problem. Unfortunately, there won't be anymore betas. We'll have to see what the GM brings in a few weeks 😠

Still broken in iOS 10 beta 6. I filed a bug report about this issue.

Same problem in beta 7. In case it saves anyone else some time, here are some things I tried:


  • I tried putting the sound directly in the main bundle as well as in Library/Sounds.
  • I tried using soundNamed: with and without the extension. The documentation does not make it clear which is correct.
  • My file is linear PCM in an AIFF container which the documentation says should be fine. The same file worked fine with the old local notification API in iOS 9.
  • I tried changing the extension from aif to aiff.

I'm still getting this in beta 8 so I've filed a bug report: rdar://28061207


I am able to get the sound to play if I delete the app, archive it from Xcode, export it as an ad hoc build, then install it through the Devices window. So I'm confident my code and sound file are correct. I specify the sound like this: [UNNotificationSound soundNamed:@"Ding.aif"] (with the extension). The file is placed in my app's main bundle, it's named Ding.aif, and it's an AIFF file in linear PCM format, 16-bit, 2 channel, 44.1kHz.

I've been able to get the sound to play once I've deleted and reinstalled the app. The sound will play as long as I don't build and run again.

I've also filed a radar rdar://28070681 I also have a related rdar://20250232 that is requesting custom sound support for watchOS (from last year.). The documentation implies that it UNNotificationSound works on watchOS, but this bug makes it nearly impossible to verify.

UNNotificationSound is available on watchOS, but the soundNamed: method is iOS-only: https://developer.apple.com/reference/usernotifications/unnotificationsound/1649031-soundnamed?language=objc So on watchOS, defaultSound is the only option.

The custom sound only works in below situations:


1 Your app is removed from your iPhone/simulator.

2 You install it.


If you run it again from Xcode, it won't work. You have to remove it from your iPhone again.


Why this is not fixed yet?

I think Apple thought this problem is subtle as for a real user, who can only installs apps from App Store, this issue is irrelevant. He can only installs and removes apps and this issue only happens in override the installed app from Xcode, which can't happen to a real user.