Reputation: 508
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
Upvotes: 3
Views: 2791
Reputation: 744
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.
Upvotes: 6
Reputation: 16790
For the second question, try AudioServicesPlaySystemSound
#define PRESS_KEY_DEFAULT_SOUND_ID 1104
- (void)playPressKeySound {
if (self.openPressSound) {
AudioServicesPlaySystemSound(PRESS_KEY_DEFAULT_SOUND_ID);
}
}
Upvotes: 0