swift – Find out how to detect whether or not a internet hosting app’s or customized keyboard textual content discipline is tapped in an iOS keyboard extension?

0
25
swift – Find out how to detect whether or not a internet hosting app’s or customized keyboard textual content discipline is tapped in an iOS keyboard extension?


I’m engaged on an iOS keyboard extension the place I’ve a customized UITextField embedded inside the keyboard itself. I must differentiate between faucets on my customized keyboard’s textual content discipline and the internet hosting app’s textual content discipline.

I at present have a flag, isSearchTextfieldTapped, to detect if the person has tapped on the keyboard’s textual content discipline. This works wonderful most often. Nevertheless, if the internet hosting app’s textual content discipline is empty and the person faucets on my keyboard’s textual content discipline first, the flag turns into true as anticipated.

The difficulty arises when the person subsequently faucets on the internet hosting app’s textual content discipline. At this level, I must reset the isSearchTextfieldTapped flag to false, however I can not work out find out how to detect that the internet hosting app’s textual content discipline has been chosen after the keyboard’s textual content discipline was tapped.

How can I detect when the person switches focus again to the internet hosting app’s textual content discipline so I can reset my flag?

Right here’s a simplified model of what I’ve tried:

    var isKeyboardTextFieldActive = false
    var isSearchTextfieldTapped = false

    override func textDidChange(_ textInput: UITextInput?) {
    print(#operate)
    
    // The app has simply modified the doc's contents, the doc context has been up to date.
    if let beforeInput = proxy.documentContextBeforeInput {
        
        if beforeInput == searchTextfield.textual content {
            isKeyboardTextFieldActive = true
        } else {
            isKeyboardTextFieldActive = false
        }
        
    } else {
        if isSearchTextfieldTapped {
            isKeyboardTextFieldActive = true
        } else {
            isKeyboardTextFieldActive = false
        }
    }
}


 extension KeyboardViewController: UITextFieldDelegate{
    func textFieldDidBeginEditing(_ textField: UITextField) {
        isSearchTextfieldTapped = true
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        isSearchTextfieldTapped = false
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here