当我收到电话时,我正在调用App.So我想播放原生声音。它的工作正常但我的问题是当手机静音时,手机只会振动。当静音播放声音时。我正在使用下面的代码来实现这一点。但它没有用。请告诉我我的工作?
// play sound when call is coming
func playSound()
{
guard let url = URL(string: "/Library/Ringtones/Opening.m4r") else
{
print("url not found")
return
}
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}
player = try? AVAudioPlayer(contentsOf: url)
player?.numberOfLoops = -1
player?.prepareToPlay()
player?.play()
}