Get System Volume iOS

后端 未结 8 2226
死守一世寂寞
死守一世寂寞 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

    0 讨论(0)
  • 2020-11-27 05:42

    For Swift 2:

    let volume = AVAudioSession.sharedInstance().outputVolume   
    print("Output volume: \(volume)")
    
    0 讨论(0)
提交回复
热议问题