Custom vibration in iOS 8 - Swift

2019-06-17 08:29发布

I'm writing a sprite kit-based app in swift and need to make a short haptic feedback using vibration

so first I imported AudioToolbox and used this

AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

and it worked well but it vibrates for too long and there's no way to control this duration.

Then after some searching I read Kevin Cao's answer here:

Are there APIs for custom vibrations in iOS?

but unfortunately AudioServicesPlaySystemSoundWithVibration private function was only usable in iOS 6.

so is there any other possible way?

1条回答
闹够了就滚
2楼-- · 2019-06-17 09:18

You need AudioServicesPlaySystemSoundWithVibration API. But unfortunately it's private and you can not publish your app :(

Check this blog post and this answer

查看更多
登录 后发表回答