Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use UITextInputMode

I need create a method which detects keyboard input language . for example when keyboard language is French does something and when is English does something else

I search on the Internet and found UITextInputMode but I don't know how to use it , I would be grateful if you help me . thanks

like image 207
Mc.Lover Avatar asked Dec 06 '25 02:12

Mc.Lover


1 Answers

It's quite simple, you can do it this way:

UITextInputMode *textInput = [UITextInputMode currentInputMode];
NSString *primaryLanguage = textInput.primaryLanguage;
NSLog(@"Current text input is: %@", primaryLanguage);

As noted in Apple docs, "The value of this property is a BCP 47 language code such as “es”, “en-US”, or “fr-CA”".

If you need to be notified about changes, you add your controller as observer for UITextInputCurrentInputModeDidChangeNotification

like image 97
Natan R. Avatar answered Dec 08 '25 16:12

Natan R.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!