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.
Asked
Active
Viewed 1,657 times
1
-
3Does 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
-
1I asked about the textfield,given answer was on UItextview.@YulianBaranetskyy – Manish Kumar Mar 15 '21 at 10:54
-
1UITextField 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
-
2There'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