gpt4 book ai didi

objective-c - 具有自定义 soundName 的 NSUserNotification

转载 作者:太空狗 更新时间:2023-10-30 03:32:31 25 4
gpt4 key购买 nike

有没有人设法让 NSUserNotification soundName 与自定义声音一起工作?我尝试使用 aif 和 caf 格式 44100KHz 16bit 2 秒的持续时间。通知在适当的时间显示,带有正确的标题和文本,但播放的是默认声音而不是我的自定义声音。

声音文件已正确复制到应用程序包中。如果我尝试这个声音工作正常:

NSSound* sound = [NSSound soundNamed:@"morse.aif"];
[sound play];

但是当我在通知中使用相同的声音时,会播放默认的通知声音:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSUserNotification* notification = [[NSUserNotification alloc]init];
notification.title = @"Titolo";
notification.deliveryDate = [NSDate dateWithTimeIntervalSinceNow:10];
notification.soundName = @"morse.aif";
[[NSUserNotificationCenter defaultUserNotificationCenter]scheduleNotification:notification];
}

我试过带扩展和不带扩展,但都没有成功。

notification.soundName = @"morse.aif";
notification.soundName = @"morse2.caf";
notification.soundName = @"morse";

这些都不起作用。

我的应用程序没有签名,也没有沙盒化,但我认为这对于用户通知来说不是必需的,除了声音问题之外,通知效果很好。

最佳答案

在我看来,这个问题是区分大小写的。使用 notification.soundName = @"Morse"; 非常适合我。正如您在 NSSound documentation 中看到的那样对于 soundNamed 声音的搜索文件夹依次为:

~/Library/Sounds
/Library/Sounds
/Network/Library/Sounds
/System/Library/Sounds

如果你查看最后一个,这可能是你试图从中提取的,因为它们是系统偏好设置中的声音,你可以看到它们的名字

Sound names

所以保留文件的大小写,省略扩展名,它应该可以按预期工作。

关于objective-c - 具有自定义 soundName 的 NSUserNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12267357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com