[英]Playing system click sound in iOS keyboard extension
我已经按照这两个链接上的说明进行操作:
并执行以下操作:
标头:
@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”字段为“是”,
然后,键盘点击声音必须需要将“允许完全访问权限”从
常规>键盘>键盘> Your_keyboard设置。
如果关闭,则无法播放键盘按键声音。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.