美文网首页
iOS手机振动反馈

iOS手机振动反馈

作者: 喵星人and亦人 | 来源:发表于2021-03-03 17:35 被阅读0次

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

相关文章

网友评论

      本文标题:iOS手机振动反馈

      本文链接:https://www.haomeiwen.com/subject/wafcqltx.html