Starting in iOS 5, users are able to create custom vibration patterns for alerts and rings. The following screenshot shows the UI for creating one (Contacts app in iOS 6):
I've been searching around, including the documentation, and I cannot find any public APIs that expose the creation or playback of custom vibrations. The closest thing is to use the AudioToolbox
framework to play a short, constant vibration:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Does anyone know if there are APIs for custom vibrations? It doesn't necessarily have to be public APIs. I'm curious to know what the Contacts app uses. Does anyone know?
P.S. Others have suggested _CTServerConnectionCreate
in CoreTelephony
(example). I tried it, but couldn't get any vibration going for some reason.
October 2015 Update:
There are new private APIs in iOS 9 to interact with the Taptic Engine in compatible devices. See Taptic in iOS 9 for more.
After serval hours' digging in the Contact App, I have figured out how it works.
ABNewPersonViewControlle invoke some class in ToneLibrary framework to do this.
The call stack looks like this:
After search "AudioServicesPlaySystemSoundWithVibration" on the web , I found nothing.
So I decide to look into it myself. It's a private function in AudioToolbox framework.
the declaration of the function is like
"inSystemSoundID" is SystemSoundID .just like "AudioServicesPlaySystemSound", pass "kSystemSoundID_Vibrate".
"arg" is not important, pass nil to it , everything will still work fine.
"vibratePattern" is a pointer of "NSDictionary", the Contact App pass into { Intensity = 1; OffDuration = 1; OnDuration = 10; } for recording user input.
But only call this function will make a vibration never stop. So I have to found some function to stop it.
The answer is "AudioServicesStopSystemSound". It's also a private function in AudioToolbox framework.
the declaration of the function is like
I guess the Contact App use AudioServicesPlaySystemSoundWithVibration in touchesBegan method, and AudioServicesStopSystemSound in touchEnd method to reach this effect.
TLVibrationController will manager a vibrate pattern object to record the process you input.
At last it generate a dictionary to pass into AudioServicesPlaySystemSoundWithVibration to replay the whole process like below:
So if you want a custom vibrations in iOS. Use AudioServicesPlaySystemSoundWithVibration and AudioServicesStopSystemSound.
There's a project called HapticKeyboard that does this. See: http://code.google.com/p/zataangstuff/source/browse/trunk/HapticKeyboard/Classes/HapticKeyboard.m?r=93
Specifically, look at the last set of functions
There are two problems: