All to known,Input method does not need to get off the grid. "Full access rights”,So according to Apple's rights,Naturally, you can not play the key tone。
but,Recent pocketed updated input method added this feature - you can even join in later versionsKey shockGot it。However, I stillNo needGet "full access"。
Then,How I do it?
iOS in the sound and vibration
In fact, the same thing。In iOS in,Actually sound vibrations,That is,First of all,As long as play sound,You can shake,Because in the iOS's api,Vibration is sound - a sound that is。
Play sound
iOS played key tone is actually playing sound,Then we can achieve the purpose of these methods:
- 使用 AudioToolbox
- Use AVFoundation
- This file directly tock.caf
- Using the system comes UIDevice.currentDevice().playInputClick()
But as you can see,They all need full access to play - but!
1、Use AudioToolbox to play system sounds actually do not need permission!
so,We have to do is find the code to the sound system by pressing the keyboard。
Different versions of iOS keyboard sound different
As we go directly to the code to play a sound,Different versions of the code sounds different,So this is why the official keyboard player is a method of using sound, UIDevice.currentDevice().playInputClick() ,Obviously,If the system version you are using is too low,It is impossible to hear the sound of the keyboard,I do not know because of the need permission,Or simply do not have this sound codes。
In short,Here I give all the code I found voice,If you also need a keyboard,You can try。
how to use
First of all,Import AudioToolbox framework import AudioToolbox ,then,Where you need to play the keyboard sound,For example, in response to key events place,transfer AudioServicesPlaySystemSound(1123) .。
It is worth mentioning that:In order to avoid blocking the main thread,You may want to play it in the child thread to go - which in turn could lead to key tone in some cases not keep pace。
Next, I give all I find the sound (vibration) Code,They are based on iOS 10 of,So the old version is not necessarily easy to use。- but at least the benefit is not required "full access" to the right?
- 1123- alphabet keyboard sound button is pressed;
- 1155- backspace sound;
- 1156- other keyboard function keys sound;
- 1519--6s peek shock effect;
- 1520--6s pop shock effect;
- 1521--6s triple shock vibration effect。
About iPhone 7
7There are more advanced series of micro vibration,Because of this I do not have corresponding equipment so I can not test whether it can use the interface,This can only be tested again in the future free。
Other discussion
As you can see,As long as the sound vibration of code into the code,Can be achieved on the button shook 6s machine,Measured by typing a little slow, then the effect is also pretty good peek - electricity costs are not costs of electricity is unknown。
I am currently just long press on off grid、On the upper and lower dotted with vibration。
Current problems such as not as pressing a button on the keyboard sound like system - this is a logical deal,Follow-up process can be optimized。
You can not cancel the previous play as fast as the system keyboard input,This results in quick succession you press the button twice, then,You may play only once key tone;Similarly shock。
Available subsequent re-study,that is all。
Original article written by LogStudio:R0uter's Blog » How pocketed the key input is to achieve sound
Reproduced Please keep the source and description link:https://www.logcg.com/archives/2740.html
I also pretend to understand the
Pretend to understand the。I'm so bad。