iOS手機振動反饋
/**
震動手機
@param type 震動類型菩咨,1:長震動憨奸,0:短震動
*/
- (void)vibrateWithiVbrateType:(YTVibrateType)type {
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
switch (type) {
case YTVibrateTypeShort:
{
AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, systemAudioCallback, NULL);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);
});
}
break;
case YTVibrateTypeLong:
{
AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, systemAudioCallback, NULL);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);
});
}
break;
default:
break;
}
}
void systemAudioCallback() {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者