How to change device Volume on iOS - not music volume

后端 未结 9 715
旧时难觅i
旧时难觅i 2020-11-28 10:30

I want to change the device volume on iOS (iphone).

I know that i can change the volume of music library with this lines below:

//implement at firs         


        
9条回答
  •  生来不讨喜
    2020-11-28 11:33

    Here's what I've done:

    func setSystemVolume(volume: Float) {
        let volumeView = MPVolumeView()
    
        for view in volumeView.subviews {
            if (NSStringFromClass(view.classForCoder) == "MPVolumeSlider") {
                let slider = view as! UISlider
                slider.setValue(volume, animated: false)
            }
        }
    }
    

    As property volume in MPMusicPlayerController was deprecate in iOS 7. This is only method you can do that.

提交回复
热议问题