简体   繁体   English

在iOS键盘扩展中播放系统点击声音

[英]Playing system click sound in iOS keyboard extension

I have followed the instructions on both these links: 我已经按照这两个链接上的说明进行操作:

How to play keyboard click sound in custom keyboard? 如何在自定义键盘中播放键盘点击声音?

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

and done the following: 并执行以下操作:

header: 标头:

@interface Key : UIView <UIInputViewAudioFeedback>

implementation: 实施:

- (BOOL) enableInputClicksWhenVisible {
    return YES;
}

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

Yet it is still not working. 但是它仍然无法正常工作。 What have I missed? 我错过了什么?

Try this code any time you want to play system click sound in a keyboard extension: 每当您想播放键盘扩展名中的系统点击声音时,请尝试以下代码:

+ (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); });
}

If your keyboard extension app contains "RequestsOpenAccess" field to YES, 如果您的键盘扩展程序应用程序的“ RequestsOpenAccess”字段为“是”,
Then keyboard click sound must need "Allow full Access" switch to On from 然后,键盘点击声音必须需要将“允许完全访问权限”从
General > Keyboard > Keyboards > Your_keyboard setting. 常规>键盘>键盘> Your_keyboard设置。

If It is Off then you can not play keyboard key sound. 如果关闭,则无法播放键盘按键声音。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM