// 震动
- (void)playVibration
{
// Register the sound completion callback.
AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate,
NULL, // uses the main run loop
NULL, // uses kCFRunLoopDefaultMode
SystemSoundFinishedPlayingCallback, // the name of our custom callback function
NULL // for user data, but we don't need to do that in this case, so we just pass NULL
);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
/**
* 系统铃声播放完成后的回调
*/
void SystemSoundFinishedPlayingCallback(SystemSoundID sound_id, void* user_data)
{
AudioServicesDisposeSystemSoundID(sound_id);
}
但如果是循环震动,例如电话响了,一直震动到接为止
/**
* 系统铃声播放完成后的回调
*/
void SystemSoundFinishedPlayingCallback(SystemSoundID sound_id, void* user_data)
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
//结束震动
- (void)endSystemSoundPlaying
{
AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);
}
本文介绍如何在iOS设备上实现单次及循环震动效果,并提供具体的Objective-C代码实现方式,包括开始和停止震动的方法。
543

被折叠的 条评论
为什么被折叠?



