UIKeyboardInputModeController *key = [UIKeyboardInputModeController sharedInputModeController];
//当前输入法
UIKeyboardInputMode *currentInputMode = [key currentInputMode];
//第三方扩展输入法
NSArray *extensionInputModes = [key extensionInputModes];
if ([extensionInputModes containsObject:currentInputMode]) {
NSLog(@"current input mode (%@) is the 3rd party input mode", currentInputMode.identifier);
} else {
NSLog(@"current input mode (%@) is build-in input mode", currentInputMode.identifier);
}
输出大概是这样的:
current input mode (com.cleanshavenapps.Pasteboard.PasteboardKeyboard) is the 3rd party input mode
current input mode (com.sogou.sogouinput.basekeyboard) is the 3rd party input mode
current input mode (com.baidu.inputMethod.keyboard) is the 3rd party input mode
current input mode (en_US@hw=US;sw=QWERTY) is build-in input mode
current input mode (zh_Hans-Pinyin@sw=Pinyin10-Simplified;hw=US) is build-in input mode
current input mode (emoji@sw=Emoji) is build-in input mode
To ask the system to switch to another keyboard, call the advanceToNextInputMode method (..) The system picks the appropriate “next” keyboard; there is no API to obtain a list of enabled keyboards or for picking a particular keyboard to switch to.
从键盘事件(比如
UIKeyboardWillShowNotification
)中,得不到使用是哪个输入法。只能得到类似下面的信息:所以感觉使用正常渠道可能得不到这个信息,不过使用私有API可以获取得到当前输入法的Id:
输出大概是这样的:
有三个是系统自带的,三个是第三方的。
共涉及到两个私有API类:分别是,
UIKeyboardInputModeController
和UIKeyboardInputMode
。这是我的头文件,你放入工程就可以用了:
没有试过,不过你可以看看UITextField或者UITextView的inputView,通过查看他们的class也许可以知道
从上述苹果的正式文档当中描述,是没有一个列表来获取的。