你是如何让iPhone在任意时间内振动的?

Kev*_*ler 14 iphone vibration

在iPhone 2.x固件中,您是否可以让iPhone在系统定义的持续时间内振动:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)

在越狱手机中,您曾经可以使用MeCCA.framework来执行此操作:

http://pastie.org/94481

MeCCA_Vibrator *v = new MeCCA_Vibrator;
v->activate(1);
sleep(5);
v->deactivate();
Run Code Online (Sandbox Code Playgroud)

但我的2.x iPhone上不存在MeCCA.framework.

Kev*_*ler 13

是的,这是过去导致AppStore拒绝的原因,可能会再次......这意味着它仍然可以做到.

回答我自己的问题,这是如何做到的:

在Build Phases中添加框架CoreTelephony.

宣布:

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;
Run Code Online (Sandbox Code Playgroud)

初始化:

connection = _CTServerConnectionCreate(kCFAllocatorDefault, &vibratecallback, &x);
Run Code Online (Sandbox Code Playgroud)

开始振动:

_CTServerConnectionSetVibratorState(&x, connection, 3, intensity, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

停止振动:

_CTServerConnectionSetVibratorState(&x, connection, 0, 0, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

此代码来自HapticKeyboard,这是一个可下载的应用程序,可在您键入时对手机进行嗡嗡声.它适用于Cydia上的越狱手机.另见我的越狱经历)

还有其他好的参考吗?