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

The problem also happens if the app reload is from TestFlight, so I suspect that it would happen with a "real" App Store update as well, not just Xcode.

Filed a radar report also (rdar://28385625). Hopefully it'll be tackled sooner rather than later.

My two cents. 🙂

I have the same problem after migration my app to iOS 10.

After the installazione via Xcode, my app set the notification but custom sound not work. If I set the notification again (without install), it works well.

Please explain exactly your meaning "If I set the notification again". Is this a practical workaround?

Fixed in iOS 10.1 beta 2.

It is great to hear that it will be fixed in 10.2, but does it mean that a custom sound does not work when it is built from Xcode , but that it WILL work when it is downloaded from App Store, even On iOS 10.0 (as long as under 30 seconds, correct file type etc.)?

Clarification/Correction: It is great to hear that it will be fixed in 10.1 beta 2. But does it mean that a custom sound only do not work when it is built from Xcode , but that it WILL work when it is downloaded from the App Store, even on iOS 10.0 (as long as under 30 seconds, correct file type etc.)? How can I be sure that the custom ring tone will work on iOS 10 for users that download from the App Store ?

It will NOT work for App Store downloads for users running iOS 10.0.x

What is the recommended workaround for this?
I have the same issue with UILocalNotification and it becomes very difficult for the user to realize someone is calling if all they get is a "ding"..


I tested the Skype iOS app, and they are able to have their custom sound, but I also noticed that they have implemented CallKit
Does that mean this bug does not impact CallKit ?



My worry is that we will be in December before the great majority has updated to 10.1, is there anything we can do in the meantime to have a 30 second ringtone with a local notification ?

You can check if you are an update running 10.0.x and alert the user to reboot the device one time (or update iOS when 10.1+ is available). It's not a pretty workaround, especially if it takes an update to add. I'm holding off until 10.1 is released for my next update of the affected app just so I don't hurt users who are not experiencing the problem.

It does seem to be fixed in 10.1 in that the custom sounds now play (and don't crash the device!), but they still stop after 5 seconds when the alert disappears.


If we're able to set 30 second sound files, then there must be a way of allowing them to play for 30 seconds? Does anyone have the solution to that?

I am running xocde 8.0 (8A218a), and this post saved my day.


I included file suffix e.g. "ForElise.caf" in sound name (it did not work without the suffix).

Deleted the app from iPhone and re-installed.

Detached it from XCode (that is also essential)


The notification then did play the custom sound. So far consistently, as long as the app is not launched from XCode.


I guessed it took me 2 hours to test all possibilities (and 20 minutes after hitting this post)

Were you able to play a custom sound for longer than 5 seconds?

I have the same issue. The sound stops after 5 seconds when alert disappears.

I'm using iOS 10.2.1 and XCode 8.2.1.


Is it a ios bug or there's a solution for that?

Please file a bug report.