How to detect when user used Password AutoFill on a UITextField

前端 未结 7 2159
半阙折子戏
半阙折子戏 2020-12-10 03:26

I\'ve implemented all the app and server changes necessary to support Password Autofill on iOS 11, and it works well. I\'d like it to work a little better.

My usern

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 04:19

    This detects when user has autofilled via passwords. It may also trigger when user pastes text from their clipboard. (If textfield is empty)

    You can probably handle the logic to remove user pasted cases with this link.. how to know when text is pasted into UITextView

      private var didAutofillTextfield: Bool = false {
        didSet {
          if didAutofillTextfield {
            // Fire analytics for user autofilling
          }
        }
      }
    
    
     func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        // If the range is {0,0} and the string count > 1, then user copy paste text or used password autofill.
        didAutofillTextfield = range == NSRange(location: 0, length: 0) && string.count > 1
        return true
      }
    

提交回复
热议问题