簡體   English   中英

NSUserNotification與自定義soundName

[英]NSUserNotification with custom soundName

有沒有人設法使用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文檔soundNamed對聲音的搜索文件夾,依次是:

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

如果您查看最后一個,這可能是您嘗試拉出的地方,因為它們是“系統偏好設置”中的聲音,您可以看到它們的名稱

聲音名稱

所以保留文件的大小寫,省略擴展名,它應該按預期工作。

如果您有多個版本的App二進制通知中心可能正在搜索錯誤的二進制文件以查找您的聲音文件。

如果您確保刪除二進制文件的任何舊副本,它應該解決問題。

來自Apple Dev論壇: https//devforums.apple.com/message/708511

如果你有多個版本的app二進制文件浮出水面,就會發生這種情況。 NotificationCenter僅對其中一個進行罰款。 如果它是沒有聲音的那個,那么它將無法工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM