1

when user sometimes copy some text from somewhere and paste on app's interface such as textfeild of username and password for simplicity.How to detect that paste event.

Willeke
  • 14,578
  • 4
  • 19
  • 47
Manish Kumar
  • 997
  • 2
  • 13
  • 30
  • 3
    Does this answer your question? [how to know when text is pasted into UITextView](https://stackoverflow.com/questions/12454857/how-to-know-when-text-is-pasted-into-uitextview) – Yulian Baranetskyy Mar 15 '21 at 10:48
  • 1
    I asked about the textfield,given answer was on UItextview.@YulianBaranetskyy – Manish Kumar Mar 15 '21 at 10:54
  • 1
    UITextField has a similar method `shouldChangeCharactersIn `, it is also mentioned on the link I posted, see: [https://stackoverflow.com/a/45960062/5049041](https://stackoverflow.com/a/45960062/5049041) – Yulian Baranetskyy Mar 15 '21 at 10:58
  • this will fail when the user is trying to paste one character,it is not passing all the conditions@YulianBaranetskyy – Manish Kumar Mar 15 '21 at 11:07
  • 2
    There's no bullet-proof way to detect that something was pasted. You need to use `shouldChangeCharactersIn` and you need to check against `UIPasteboard` - that's the principle. How picky it is though, is up to your code. You could also monitor `UIPasteboardChanged` to see if anything was copied into clipboard, and then compare it to the changes in `shouldChangeCharactersIn`. – timbre timbre Mar 15 '21 at 14:26

0 Answers0