根据Are there APIs for custom vibrations in iOS?(从iOS 5/6开始),内部将AudioServicesPlaySystemSoundWithVibration()用于iOS上的振动。
但是我尝试使用MobileSubstrate挂接到iOS 7,
AudioServicesPlaySystemSoundWithVibration <-似乎从未被调用
AudioServicesPlaySystemSound <-切换静音开关但没有其他振动时调用
AudioServicesPlayAlertSound <-似乎从未被调用
所以问题是,从iOS 7开始,内部使用了什么功能(大概仍在AudioToolkit.framework中,但也许没有)?
最佳答案
最近,我研究了当您切换静音开关或连接电源时,SpringBoard如何发挥振动。它仅使用带有相同参数的AudioServicesPlaySystemSound
(0x452用于充电,0x453用于静默开关)无声开关。添加公告后,我唯一看到AudioServicesPlaySystemSoundWithVibration
调用的地方。
这适用于iOS 5-7。唯一的区别是iOS 5公告使用AudioServicesPlaySoundWithBehavior
,因为AudioServicesPlaySystemSoundWithVibration
仅在iOS 6开始可用。
更新
首选项应用程序使用0x547或0x546作为参数的AudioServicesPlaySystemSound
。使用MobileSubstrate看不到它的原因是,“首选项”应用程序在运行时使用AudioToolbox
加载了dlopen
框架,然后使用AudioServicesPlaySystemSound
获取指向dlsym
的指针。在这种情况下,要挂接函数,您需要等到“首选项”应用程序获得指针后再挂接它。
更新2
SpringBoard还使用CoreMedia.framework API来播放振动。这里的所有论据只是从反汇编中得出的猜测。我对C结构参数和浮点指令没有太多经验。
FigVibratorPlayVibrationWithDictionary(CFDictionaryRef pattern, BOOL, float)
。最后两个参数对我来说是未知的-它们设置为NO和1.0f。 FigVibratorPlayVibration(float, CMTime, CMTime, CTime)
。 上面的功能最有可能被iOS使用,但是还有其他一些功能值得一提:
FigVibratorStartOneShot(float, CMTime)
FigVibratorStartRepeating
。第一个参数可能是浮点数,但其他参数不知道-它是一些CMTime参数。 关于ios - iOS 7在内部称为振动(已更改!)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23642902/