0

I'd like to use a custom sound for Notification Center, but cannot find much documentation on this. I know how to assign a sound to a notification, and I know how to copy new sound files to ~/Library/Sounds then use these new sounds. My app is sandboxed so I of course have to ask the user to confirm they want to install the new sounds, but am concerned about App Store rejection based on this App Store rule:

2.15 Apps must be self-contained, single application installation bundles, and cannot install code or resources in shared locations

Anyways, is it possible to use a custom sound with a NSUserNotification without copying a resource to ~/Library/Sounds ?

Seems like there is documentation for this on iOS, but nothing for OS X.

Thanks in advance.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • `NSNotification` and `NSNotificationCenter` have nothing to do with the Notification Center in the OS X UI (the thing which slides in from the right). And they have nothing to do with sounds. You presumably are talking about `NSUserNotification` and `NSUserNotificationCenter`. – Ken Thomases Dec 26 '15 at 06:31

1 Answers1

2

The comment by the declaration of the soundName property of the NSUserNotification class in the headers reads (emphasis added):

The name of the sound file in the resources of the application bundle to play when the notification is delivered. NSUserNotificationDefaultSoundName can be used to play the default Notification Center sound. A value of 'nil' means no sound.

So, you can simply ship a sound file in your app bundle's resources and use its name for the user notification's soundName. Almost certainly, this is similar to the +[NSSound soundNamed:] method, so you should pass the file name minus the file extension.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • 2
    Unfortunately, this doesn't seem to be working. It should be the answer, however. I can use NSSound soundNamed: to play the sound but when trying to use the same sound on the NSUserNotification, nothing plays. I'm assuming this is a bug in OS X. The only way I can get the notification sound to change is if the custom sounds are copied into ~/Library/Sounds. – William Gustafson Dec 26 '15 at 18:44
  • 1
    For now, I am just going to play the custom sound manually using something like the following: `[[NSSound soundNamed:[self.prefsNotifSoundButton titleOfSelectedItem]] play];` – William Gustafson Dec 26 '15 at 19:02