3

I'm working on iOS 8 custom keyboard extension right now, and there are some issues that I cannot figure out.

First, I think the UITextInputDelegate Methods are not working as I expected.

Does this sound right: selectionWillChange: and selectionDidChange: methods should be called when user long-presses typing area? And textWillChange: and textDidChange: methods should be called whenever the text is literally changing?

Actually, what I observed is that, when I changed selection in text input area, textWillChange: and textDidChange: are called, and I cannot get a clue that the other two methods are called in what condition. If anyone knows about the usage of these delegate methods, please let me know.

Second, I know the playInputClick: method can be used to virtualize keyboard click sound in custom keyboard. As this is applicable in a normal situation, I found it impossible to apply in iOS 8 custom keyboard extension. My app consists of one keyboard view controller, and custom view that subclasses UIView is added to this view controller. My approach is that UIInputViewAudioFeedback delegate is declared in this custom view, enableInputClicksWhenVisible method is returning YES, class method that calls [[UIDevice currentDevice] playInputClick] is set, then this method is called wherever the keyboard sound is needed: which is not working at all.

Is my approach is wrong in any way? If anyone has succeeded in using playInputClick method, please share your wisdom.

Thank you

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
Tack-Gyu Lee
  • 448
  • 3
  • 11
  • Consider splitting this into two separate questions. – tar Aug 06 '14 at 04:05
  • 1
    Answered your first question in the separate question you posted on SO (http://stackoverflow.com/q/25158161/2057171). As for `playInputClick` it is disabled on custom keyboards at this point in time, you have to use custom audio playback. – Albert Renshaw Aug 10 '14 at 04:12
  • @AlbertRenshaw which custom audio playback approach have you had success with in the KeyboardExtension? Those we've tried don't seem to work outside of the simulator. – wxs Sep 22 '14 at 21:15
  • @wxs I had it working at one point after gold master was released, it was laggy, but it's gotten better depending on the file type you use, but I no longer have the code /: I'm sorry. But don't lose hope, there is a way I can guarantee it because I've seen it work haha, good luck! Bookmark this link and come share an answer with us once you figure it out! – Albert Renshaw Sep 22 '14 at 22:36

2 Answers2

6

It is best to play the Audio on a queue rather than in the UI key handler

func playPressKeySound() {
    let PRESS_KEY_DEFAULT_SOUND_ID: SystemSoundID = 1104
    dispatch_async(dispatch_get_main_queue()) {
            AudioServicesPlaySystemSound(PRESS_KEY_DEFAULT_SOUND_ID)
        }
}

NOTE: this only works if the keyboard has Full Access switched on, so best test there is full access before calling, otherwise the keyboard can suffer long pauses.

Guy Brooker
  • 726
  • 7
  • 11
0

For the second question, try AudioServicesPlaySystemSound

#define PRESS_KEY_DEFAULT_SOUND_ID 1104

- (void)playPressKeySound {
    if (self.openPressSound) {
        AudioServicesPlaySystemSound(PRESS_KEY_DEFAULT_SOUND_ID);
    }
}
ljk321
  • 16,242
  • 7
  • 48
  • 60