-1
我必須在swift 2中導入設置和獲取設備音量?如何在設備上簡單地設置靜音?是否存在簡單的代碼來做到這一點?如何在Swift 2上設置主音量?
我必須在swift 2中導入設置和獲取設備音量?如何在設備上簡單地設置靜音?是否存在簡單的代碼來做到這一點?如何在Swift 2上設置主音量?
首先,進口MediaPlayer
:
import MediaPlayer
如果你想同時使用的應用程序,以靜音,去AppDelegate
並輸入以下代碼,在applicationDidFinishLaunchingWithOptions
:
(MPVolumeView().subviews.filter{NSStringFromClass($0.classForCoder) ==
"MPVolumeSlider"}.first as? UISlider)?.setValue(0, animated: false)
//# MARK: 0 represents the lowest volume and 1 the highest volume from "setValue(0, animated: false)"
來自:斯威夫特:如何以編程方式設置iPhone卷](http://stackoverflow.com/questions/36322856/swift-how-to-set-the-iphone-volume-programmatically) –