Reputation: 11523
I'd like to know when dictation has end (ideally also when it started).
My UIViewController
which includes the UITextView
conforms to the UITextInputDelegate
protocol.
To make it work I had to subscribe to the UITextInputCurrentInputModeDidChangeNotification
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeInputMode:", name: UITextInputCurrentInputModeDidChangeNotification, object: nil)
}
and add the delegate there (it didn't work simply adding it to the viewDidLoad())
func changeInputMode(sender : NSNotification) {
textView.inputDelegate = self
}
Starting and stopping dictation the UITextInput now correctly calls the required delegate methods:
func selectionWillChange(textInput: UITextInput){ }
func selectionDidChange(textInput: UITextInput){ }
func textWillChange(textInput: UITextInput){ }
func textDidChange(textInput: UITextInput){ }
However what doesn't get called is
func dictationRecordingDidEnd() {
println("UITextInput Dictation ended")
}
Why? How can I get notified/call a method on dictation having ended?
Upvotes: 5
Views: 1211
Reputation: 11523
Okay, here's what worked for me not using the UITextInput
protocol but the UITextInputCurrentInputModeDidChangeNotification
instead.
func changeInputMode(sender : NSNotification) {
var primaryLanguage = textView.textInputMode?.primaryLanguage
if primaryLanguage != nil {
var activeLocale:NSLocale = NSLocale(localeIdentifier: primaryLanguage!)
if primaryLanguage == "dictation" {
// dictation started
} else {
// dictation ended
}
}
}
Upvotes: 4