[英]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.