Playing a sound on tap on a key on custom number pad
-
16-06-2021 - |
Question
I am creating and putting a custom number bar on top of regular keypad. Now, when I tap on the keys in the numberpad, I want the regular keyboard sound to play. I am using the below code in the button pressed delegate. Log statement prints but there is no sound on my device. A tap on any key on the regular keypad play the sound. Do I need to enable something?
- (void)buttonPressed:(id)iSender {
NSLog(@"Button is pressed");
[[UIDevice currentDevice] playInputClick];
}
Solution
To quote the docs:
Use this method to play the standard system keyboard click in response to a user tapping in a custom input or keyboard accessory view. A click plays only if the user has enabled keyboard clicks in Settings > Sounds, and only if the input view is itself enabled and visible.
To enable a custom input or accessory view for input clicks, perform the following two steps:
Adopt the UIInputViewAudioFeedback protocol in your input view class. Implement the enableInputClicksWhenVisible delegate method to return YES.
Sounds like that method is not useful as a general-purpose "play a click" method. It's tightly coupled to input views.