我有此代码。
import AudioToolbox.AudioServices
if restoreData.boolForKey("VibrationSwitchButton") == true {
vibra()
}
func vibra() {
if UIDevice.currentDevice().model == "iPhone" {
let systemSoundIDButton : SystemSoundID = 4095
AudioServicesPlayAlertSound(SystemSoundID(systemSoundIDButton))
// print("VIBRA")}
}
我有一个UISwitch
,可以激活和停用此代码路径。开关可以正常工作,但是如果我在常规选项(声音)中激活振动,则也无法从设置中取消激活,反之亦然。
如何概括我的配置?如果必须在常规设置下振动,则可以在我的应用上停用。
Swift 2.0和Xcode 7.1
使用AudioServicesPlaySystemSound
代替AudioServicesPlayAlertSound
。
示例代码:
if restoreData.boolForKey("VibrationSwitchButton") == true {
vibra()
} else {
soundOnly()
}
func soundOnly() {
if UIDevice.currentDevice().model == "iPhone" {
let systemSoundIDButton : SystemSoundID = 4095
AudioServicesPlaySystemSound(SystemSoundID(systemSoundIDButton))
// print("Sound Only")
}
}