10

カスタムサウンドで動作するように 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";     

これらのどれも機能しません。

私のアプリケーションは署名されておらず、サンドボックス化されていませんが、ユーザー通知には必要ないと思います。音の問題は別として、通知はうまく機能します。

4

2 に答える 2

2

複数のバージョンのアプリ バイナリがある場合、通知センターがサウンド ファイルの間違ったバイナリを検索している可能性があります。

バイナリの古いコピーを確実に削除すると、問題が解決するはずです。

Apple Dev フォーラムから: https://devforums.apple.com/message/708511

これは、複数のバージョンのアプリ バイナリがあちこちにある場合に発生する可能性があります。NotificationCenter はそのうちの 1 つだけに罰金を科します。音のないものだとうまくいきません。

于 2015-03-23T02:56:57.947 に答える