How do you make the iPhone vibrate for arbitrary durations?

假装没事ソ 提交于 2019-11-28 05:06:17
KevinButler

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?

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

Not only is this impossible to do using the SDK, but it's also the first item in the Unofficial App Store Rejection Criteria.

iOS 5 has implemented Custom Vibrations mode. So in some cases variable vibration is acceptable. The only thing is unknown what library deals with that (pretty sure not CoreTelephony) and if it is open for developers.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!