Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make the iPhone vibrate for arbitrary durations?

In the iPhone 2.x firmware, can you make the iPhone vibrate for durations other than the system-defined:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

In jailbroken phones, you used to be able to use the MeCCA.framework to do this:

http://pastie.org/94481

MeCCA_Vibrator *v = new MeCCA_Vibrator;
v->activate(1);
sleep(5);
v->deactivate();

But MeCCA.framework doesn't exist on my 2.x iPhone.

like image 894
KevinButler Avatar asked Nov 05 '08 16:11

KevinButler


2 Answers

Yes, this is something that has caused AppStore rejections in the past, and probably will again...which means it is still possible to do it.

Answering my own question, here's how to do it:

Add framework CoreTelephony in Build Phases.

declare:

extern void * _CTServerConnectionCreate(CFAllocatorRef, int (*)(void *, CFStringRef, CFDictionaryRef, void *), int *);
extern int _CTServerConnectionSetVibratorState(int *, void *, int, int, float, float, float);

static void* connection = nil;
static int x = 0;

initialize:

connection = _CTServerConnectionCreate(kCFAllocatorDefault, &vibratecallback, &x);

start vibration:

_CTServerConnectionSetVibratorState(&x, connection, 3, intensity, 0, 0, 0);

stop vibration:

_CTServerConnectionSetVibratorState(&x, connection, 0, 0, 0, 0, 0);

This code is from HapticKeyboard, a downloadable application that buzzes the phone as you type. It is available for jailbroken phones on Cydia. See also my jailbreaking experience)

Any other good references?

like image 188
KevinButler Avatar answered Sep 18 '22 18:09

KevinButler


There's no way to do this using the SDK, sorry.

like image 34
Ben Gottlieb Avatar answered Sep 17 '22 18:09

Ben Gottlieb