2015-11-01 17 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") 
} 
}