播放系统咔嗒声

问题描述:

我按照这些链接上都说明:播放系统咔嗒声

How to play keyboard click sound in custom keyboard?

https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html

,并做了以下内容:

头:

@interface Key : UIView <UIInputViewAudioFeedback> 

实施:

- (BOOL) enableInputClicksWhenVisible { 
    return YES; 
} 

- (void)tapped:(UITapGestureRecognizer *)sender 
{ 
    [[UIDevice currentDevice] playInputClick]; 
    [self.delegate keyHit:_title]; 
} 

但它仍然无法正常工作。我错过了什么?

试试这个代码,你想在键盘延长播放系统咔哒声的任何时间:

+ (void)keyboardClickSound { 

    // Check system preference for current setting of Keyboard Click Sound. 
    CFStringRef applicationID = CFSTR("/var/mobile/Library/Preferences/com.apple.preferences.sounds"); 
    Boolean keyExistsAndHasValidFormat; 
    BOOL enableInputClicks 
    = CFPreferencesGetAppBooleanValue(CFSTR("keyboard"), applicationID, &keyExistsAndHasValidFormat); 

    // Note: If the key does not exist because it has never been changed by a user, 
    //  set it to the default, YES. 
    if (!keyExistsAndHasValidFormat) 
     enableInputClicks = YES; 

    // Play Keyboard Click Sound, if enabled. 
    // Note: If Open Access=Off, no click sound. 
    if (enableInputClicks) 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), 
        ^{ AudioServicesPlaySystemSound(1104); }); 
} 

如果你的键盘扩展应用程序包含“RequestsOpenAccess”字段设置为yes,
然后单击键盘的声音一定需要“允许完全访问“从
开始打开 常规>键盘>键盘> Your_keyboard设置。

如果它关闭,那么您将无法播放键盘按键声音。