2016-08-02 24 views

回答

1

首先,進口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)" 
+1

來自:斯威夫特:如何以編程方式設置iPhone卷](http://stackoverflow.com/questions/36322856/swift-how-to-set-the-iphone-volume-programmatically) –