Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom vibration in iOS 8 - Swift

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?

like image 666
Ahmad Ismail Avatar asked May 15 '15 20:05

Ahmad Ismail


People also ask

How do I make my iPhone vibrate with Swift?

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.

How do you make a custom vibration on Apple?

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.


1 Answers

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

Check this blog post and this answer

like image 94
pulp Avatar answered Oct 21 '22 09:10

pulp