2014-09-27 70 views
0

我按照這些鏈接上都說明:播放系統咔嗒聲

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

但它仍然無法正常工作。我錯過了什麼?

回答

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); }); 
} 
1

如果你的鍵盤擴展應用程序包含「RequestsOpenAccess」字段設置爲yes,
然後單擊鍵盤的聲音一定需要「允許完全訪問「從
開始打開 常規>鍵盤>鍵盤> Your_keyboard設置。

如果它關閉,那麼您將無法播放鍵盤按鍵聲音。