Making tapped sound with UIInputViewAudioFeedback protocol

audio - iPhone: how to make key click sound for custom keypad? - Stack Overflow

I found a comment below at the same page :
As of iOS 4.2, adopt the UIInputViewAudioFeedback protocol on a custom subclass of UIView. Make this view your "inputView" and then call "playInputClick" at the appropriate time.
So I tried this way using UIInputViewAudioFeedback protocol.

I have to write a protocol name at the top of NumberPad.h :
@interface NumberPad : UIView <UIInputViewAudioFeedback> {
And I put the next code in NumberPad.m as reference says :
- (BOOL) enableInputClicksWhenVisible {
    return YES;
And I also made UIDevice object in initializer of NumberPad.m :
currentDevice = [[UIDevice currentDevice] retain];
'cuurentDevice' is instance of NumberPad class.

And I added playInputClick method at the proper place :
- (void) numberTappedHandler:(UIButton *)button {
    [currentDevice playInputClick];
And the result is GREAT!
This is not loud!
Same volume of sound with others!

custom number pad

Finally I have made my custom number pad!
Develop | Comments(1) | Trackback(0)
Comment is pending approval.
Comment is pending blog author's approval.