【发布时间】:2014-05-02 02:38:22
【问题描述】:
在我们的应用中,我们想检测当前的键盘语言。例如,如果用户在 Settings->General->Keyboard->Keyboards 下设置了多种语言键盘,我们想知道他们输入的是什么语言,并在更改时从 NSNotificationCenter 获得通知。
- (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);
}
我们在这段代码中发现的是,当用户使用键盘上的地球图标切换键盘时,通知会适当地触发,但是当我们迭代 UITextInputModes 时,它们以相同的顺序出现,没有(明显)指示除非我们使用现已弃用的 [UITextInputMode currentInputMode],否则这是当前的。
我找不到任何说明 Apple 建议替代这个现已弃用的功能的文档。有几个 SO 线程提到了弃用,但我没有找到解决方案。有任何想法吗?提前致谢。
【问题讨论】:
标签: ios iphone internationalization keyboard