2015-11-01 43 views
2

我有这样的代码斯威夫特SystemSoundIDButton振动

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

回答

0

使用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") 
} 
}