Fra*_*rio 8 macos objective-c osx-mountain-lion nsusernotification
有没有人设法使用NSUserNotification soundName来处理自定义声音?我试过aif和caf格式44100KHz 16bit 2秒的持续时间.通知会在适当的时间显示,并带有正确的标题和文字,但会播放默认声音而不是我的自定义声音.
声音文件已在应用程序包中正确复制.如果我试试这个声音可以正常工作:
NSSound* sound = [NSSound soundNamed:@"morse.aif"];
[sound play];
Run Code Online (Sandbox Code Playgroud)
但是当我在通知中使用相同的声音时,会播放默认通知声音:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
我尝试了无延伸,但没有成功.
notification.soundName = @"morse.aif";
notification.soundName = @"morse2.caf";
notification.soundName = @"morse";
Run Code Online (Sandbox Code Playgroud)
这些都不起作用.
我的应用程序没有签名,也没有沙盒,但我不认为这对用户通知是必要的,除了声音问题,通知工作得很好.
在我看来,这个问题是区分大小写的.使用notification.soundName = @"Morse";效果非常适合我.正如你可以看到在NSSound文档用于soundNamed对声音是,为了在搜索文件夹:
~/Library/Sounds
/Library/Sounds
/Network/Library/Sounds
/System/Library/Sounds
Run Code Online (Sandbox Code Playgroud)
如果您查看最后一个,这可能是您尝试拉出的地方,因为它们是"系统偏好设置"中的声音,您可以看到它们的名称

所以保留文件的大小写,省略扩展名,它应该按预期工作.
| 归档时间: |
|
| 查看次数: |
2583 次 |
| 最近记录: |