And*_*rew 70 iphone-vibrate vibration ios
从iOS 5开始,用户可以为警报和响铃创建自定义振动模式.以下屏幕截图显示了用于创建一个UI(iOS 6中的Contacts应用程序)的UI:
我一直在搜索,包括文档,我找不到任何公开的API来揭示自定义振动的创建或回放.最接近的是使用AudioToolbox
框架来发挥短暂的持续振动:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)
有谁知道是否有自定义振动的API?它不一定是公共API.我很想知道联系人应用程序使用的是什么.有人知道吗?
PS其他人_CTServerConnectionCreate
在CoreTelephony
(例子)中提出了建议.我试过了,但由于某种原因无法振动.
2015年10月更新:
iOS 9中有新的私有API可与兼容设备中的Taptic Engine进行交互.有关详细信息,请参阅iOS 9中的Taptic.
Kev*_*Cao 102
经过serval小时搜索联系应用程序后,我已经弄清楚它是如何工作的.
ABNewPersonViewControlle调用ToneLibrary框架中的一些类来执行此操作.
调用堆栈如下所示:
0 CoreFoundation 0x3359a1d4 CFGetTypeID + 0
1 CoreFoundation 0x33596396 __CFPropertyListIsValidAux + 46
2 CoreFoundation 0x33517090 CFPropertyListCreateData + 124
3 AudioToolbox 0x38ac255a AudioServicesPlaySystemSoundWithVibration + 158
5 ToneLibrary 0x35a7811a -[TLVibrationRecorderView vibrationComponentDidStartForVibrationRecorderTouchSurface:] + 38
6 ToneLibrary 0x35a772b2 -[TLVibrationRecorderTouchSurface touchesBegan:withEvent:] + 342
7 UIKit 0x3610f526 -[UIWindow _sendTouchesForEvent:] + 314
8 UIKit 0x360fc804 -[UIApplication sendEvent:] + 376
Run Code Online (Sandbox Code Playgroud)
在网上搜索"AudioServicesPlaySystemSoundWithVibration"之后,我一无所获.
所以我决定自己调查一下.它是AudioToolbox框架中的私有函数.
函数的声明就像
void AudioServicesPlaySystemSoundWithVibration(SystemSoundID inSystemSoundID,id arg,NSDictionary* vibratePattern)
Run Code Online (Sandbox Code Playgroud)
"inSystemSoundID"是SystemSoundID.就像"AudioServicesPlaySystemSound"一样,传递"kSystemSoundID_Vibrate".
"arg"并不重要,传递给它,一切都会正常.
"vibratePattern"是"NSDictionary"的指针,Contact App传递给{Intensity = 1; OffDuration = 1; OnDuration = 10; 用于记录用户输入.
但只有调用此功能才能使振动永不停止.所以我必须找到一些功能来阻止它.
答案是"AudioServicesStopSystemSound".它也是AudioToolbox框架中的私有函数.
函数的声明就像
void AudioServicesStopSystemSound(SystemSoundID inSystemSoundID)
Run Code Online (Sandbox Code Playgroud)
我猜联系应用程序在touchesBegan方法中使用AudioServicesPlaySystemSoundWithVibration,而在TouchEnd方法中使用AudioServicesStopSystemSound来达到此效果.
TLVibrationController将管理振动模式对象以记录您输入的进程.
最后生成一个字典,传入AudioServicesPlaySystemSoundWithVibration,重放整个过程,如下所示:
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array ];
[arr addObject:[NSNumber numberWithBool:YES]]; //vibrate for 2000ms
[arr addObject:[NSNumber numberWithInt:2000]];
[arr addObject:[NSNumber numberWithBool:NO]]; //stop for 1000ms
[arr addObject:[NSNumber numberWithInt:1000]];
[arr addObject:[NSNumber numberWithBool:YES]]; //vibrate for 1000ms
[arr addObject:[NSNumber numberWithInt:1000]];
[arr addObject:[NSNumber numberWithBool:NO]]; //stop for 500ms
[arr addObject:[NSNumber numberWithInt:500]];
[dict setObject:arr forKey:@"VibePattern"];
[dict setObject:[NSNumber numberWithInt:1] forKey:@"Intensity"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict);
Run Code Online (Sandbox Code Playgroud)
因此,如果您想在iOS中进行自定义振动.使用AudioServicesPlaySystemSoundWithVibration和AudioServicesStopSystemSound.
归档时间: |
|
查看次数: |
44787 次 |
最近记录: |