NSUserNotification 自定义声音(OS X,沙盒应用)

NSUserNotification Custom Sound (OS X, Sandboxed App)

我想为通知中心使用自定义声音,但找不到太多相关文档。我知道如何为通知分配声音,我知道如何将新声音文件复制到 ~/Library/Sounds 然后使用这些新声音。我的应用程序是沙盒的,所以我当然必须要求用户确认他们想要安装新的声音,但我担心基于此 App Store 规则的 App Store 拒绝:

2.15 应用必须是独立的、单一的应用安装包,并且不能在共享位置安装代码或资源

无论如何,是否可以在不将资源复制到 ~/Library/Sounds 的情况下将自定义声音与 NSUserNotification 一起使用?

似乎有 documentation for this on iOS,但 OS X 没有。

提前致谢。

headers中NSUserNotificationclass的soundName属性声明的注释如下(重点加):

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.

因此,您只需在应用程序包的资源中发送一个声音文件,并将其名称用于用户通知 soundName。几乎可以肯定,这类似于 +[NSSound soundNamed:] method,因此您应该传递文件名减去文件扩展名。