UITextView in iOS 13 doesn't respect autocapitalizationType.sentences when shouldChangeTextInRange is used

The title says it all. These are my development setup


1) Xcode 11

2) A simple project targeting iOS 13

3) An iPhone 8 running iOS 13.1.2 (17A860)


I created a new Project in Xcode 11, a simple View controller that contains a UITextView. The TextView has autoCapitalizationType as "Sentences". Then I implemented the delegate method "shouldChangeTextInRange" method. See the code below



import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var textView: UITextView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.textView.delegate = self
        self.textView.autocapitalizationType = .sentences
    }
}

extension ViewController: UITextViewDelegate {
    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        //I wanted to do some other modifications here, but for now just setting the text manually and returning false
        if let oldString = textView.text {
            let newString = oldString.replacingCharacters(in: Range(range, in: oldString)!,
                                                          with: text)
            textView.text = newString
        }
        return false
    }
}


As you can see above, I am just manually setting the same text that is entered by user in shouldChangeTextInRange method and return false. But when I type, the first character gets added in caps as it should. The second character correctly gets added in small letter. From third character onwards everything is caps. More over, the keyboard Caps button automatically getting selected after each characters is typed.


This is only on iOS 13. I didn't get this in previous iOS versions. And it is not happening for other autocapitalizationType values like Words, None etc. I tried to set autocapitalizationType in code and in storyboard, with same results.


Let us know if any other information is needed. Thanks in advance.

Can anyone answer this?


Just to clear a possible confusion from the above comment, the sample project I mentioend above is targetting iOS 13. But this issue can be reproduced even if the app is targeting iOS 12. So far, we have been able to reproduce this only on iOS 13 devices though.

I'm having the same problem. There is also an unanswered StackOverflow question about it here:

https://stackoverflow.com/questions/58425591/returning-false-in-shouldchangetextinrange-method-auto-capitalize-all-letters


Any ideas? 🙂

I tested the same problem (XCode 11.2 / iOS 13.2 simulator).


It seems it may occuralso, rarely, with .words.

I typed at the end of the text view all in lowercase, but got:

Add Some Text. And MOre. // O should have been lowercase.

But I could not repeat the issue. Did I mistype ?


Anyway, there is surely a bug to report for sentences.

I have the same issue. Help, please

Hello, any solutions so far for this issue?

I have same issue with my app, any udpate on it. it normaly come when I select any suggection from keyword suugestions.
please udpate if you have any luck wtih it

I'm also experiencing this bug. this is terrible.

Clear text to fix. Works for me:

textView.attributedText = nil textView.attributedText = newText

UITextView in iOS 13 doesn't respect autocapitalizationType.sentences when shouldChangeTextInRange is used
 
 
Q