如何通过应用程序中的播放器播放 UNNotificationSound.default()?

问题描述 投票:0回答:2

我在iOS应用程序中有一个铃声列表,另外,其中一个选项应该是系统默认铃声,用户可以选择并播放。 如何获取用户选择的铃声以及如何使用

AVAudioPlayer
在应用程序内播放此铃声,或者至少获取用户选择的文件的名称?

ios swift avaudioplayer uilocalnotification audiotoolbox
2个回答
0
投票

添加

import AudioToolbox
,然后添加
AudioServicesPlaySystemSound(SystemSoundID(1000))
以播放系统声音。

请参阅音频服务以获取声音列表。希望这些声音之一是 as

UNNotificationSound.default

编辑

1002 似乎是默认通知的正确声音 ID。


0
投票

发布纯声音通知只会播放声音:

let content = UNMutableNotificationContent()
content.sound = UNNotificationSound.default
let request = UNNotificationRequest(identifier: "Sample", content: content, trigger: nil)
UNUserNotificationCenter.current().add(request) { error in
    print("Error \(error.localizedDescription)")
}
© www.soinside.com 2019 - 2024. All rights reserved.