AVAudioSession setCategory Swift 4.2 iOS 12 - Play Sound on Silent

前端 未结 9 1961
醉酒成梦
醉酒成梦 2020-12-13 06:06

To play sound even on Silent mode I use to use below method. But how it\'s not working.

// Works on Swift 3  
do {
    try AVAudioSession.sharedInstance().se         


        
9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 06:18

    Code for swift 4 :

    do {
            try AKSettings.setSession(category: .playback, with: [])
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, options: [])
            try AVAudioSession.sharedInstance().setActive(true)
    
    
        } catch {
            print(error)
        }
    

    Hope that helps

提交回复
热议问题