【问题标题】:Playing system click sound in iOS keyboard extension在 iOS 键盘扩展中播放系统点击声音
【发布时间】:2014-09-27 13:56:14
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios audio ios-keyboard-extension


    【解决方案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); });
    }
    

    【讨论】:

      【解决方案2】:

      如果您的键盘扩展应用包含“RequestsOpenAccess”字段为 YES,
      然后键盘点击声音必须需要“允许完全访问”从
      切换到开启 常规 > 键盘 > 键盘 > Your_keyboard 设置。

      如果它是关闭的,那么你就不能播放键盘按键声音。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-04
        相关资源
        最近更新 更多