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?
To make an iPhone vibrate using swift we'll use two different methods. First create a new project and add Four different buttons to the main View controller. Now import the AudioToolbox framework in your view controller class. This will generate a long vibrating feedback on your device.
Tap Ringtone or Text Tone, depending on what your vibration to be associated with. Tap Vibration. Select a custom vibration under the Standard list, or tap Create New Vibration under Custom. If you chose the latter, tap the screen to create a vibration pattern, and when you're happy with it, tap Save.
You need AudioServicesPlaySystemSoundWithVibration API. But unfortunately it's private and you can not publish your app :(
Check this blog post and this answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With