Get System Volume iOS

后端 未结 8 2281
死守一世寂寞
死守一世寂寞 2020-11-27 05:02

My case is simple: I need to play a warning signal and want to make sure the user will hear it, so I want to check the system volume.

How can I find out what the cur

8条回答
  •  半阙折子戏
    2020-11-27 05:38

    Swift 3.1

    let audioSession = AVAudioSession.sharedInstance()
    var volume: Float?
    do {
        try audioSession.setActive(true)
        volume = audioSession.outputVolume
    } catch {
        print("Error Setting Up Audio Session")
    }
    

    audioSession.setActive(true) - important

提交回复
热议问题