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);
}