0

我已按照这两个链接上的说明进行操作:

如何在自定义键盘中播放键盘点击声音?

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];
}

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

4

2 回答 2

1

每当您想在键盘扩展中播放系统点击声音时,请尝试此代码:

+ (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); });
}
于 2015-05-10T15:24:50.907 回答
1

如果您的键盘扩展应用程序包含“RequestsOpenAccess”字段为 YES,
则键盘点击声音必须需要“允许完全访问”从
General > Keyboard > Keyboards > Your_keyboard 设置切换到 On。

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

于 2015-05-11T13:47:01.463 回答