In our application, we want to determine the current keyboard language. For example, if a user installs several language keyboards in the "Settings" - "Basic" - "Keyboard" - "Keyboards" section, we would like to know what language they are typing in and receive a notification from NSNotificationCenter when this changes.
- (void)viewDidLoad { [super viewDidLoad]; NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter]; [nCenter addObserver:self selector:@selector(languageChanged:) name:UITextInputCurrentInputModeDidChangeNotification object:nil]; [self languageChanged:nil]; } -(void)languageChanged:(NSNotification*)notification { for(UITextInputMode *mode in [UITextInputMode activeInputModes]) { NSLog(@"Input mode: %@", mode); NSLog(@"Input language: %@", mode.primaryLanguage); } NSLog(@"Notification: %@", notification); UITextInputMode *current = [UITextInputMode currentInputMode]; NSLog(@"Current: %@", current.primaryLanguage); }
What we found with this code is that the notification works properly when the user switches the keyboard using the globe icon on the keyboard, but when we repeat UITextInputModes, they are displayed in the same order, but not (visible) which is current if we do not use the obsolete [UITextInputMode currentInputMode].
I cannot find the documentation in which Apple suggested an alternative to this deprecated functionality. There are several SO threads that mention failure, but none of them are found with solutions. Any ideas? Thanks in advance.
source share