我在iOS应用程序中有一个铃声列表,另外,其中一个选项应该是系统默认铃声,用户可以选择并播放。 如何获取用户选择的铃声以及如何使用
AVAudioPlayer
在应用程序内播放此铃声,或者至少获取用户选择的文件的名称?
添加
import AudioToolbox
,然后添加AudioServicesPlaySystemSound(SystemSoundID(1000))
以播放系统声音。
请参阅音频服务以获取声音列表。希望这些声音之一是 as
UNNotificationSound.default
。
编辑
1002 似乎是默认通知的正确声音 ID。
发布纯声音通知只会播放声音:
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)")
}