方法
目前可以通過獲得當(dāng)前的UITextInputMode
實例來判斷是否屬于第三方輸入法
- 若是系統(tǒng)輸入法龄捡,實例為
UIKeyboardInputMode
(私有API)對象。 - 若是第三方(百度悠砚、搜狗等)输钩,實例為
UIKeyboardExtensionInputMode
(私有API)對象犯戏。
借助這點奋渔,可以寫出以下代碼浸颓。
// 方法一
- (BOOL)isThirdPartyKeyboard {
UITextInputMode *currentInputMode = [[UIApplication sharedApplication] textInputMode];
if ([[currentInputMode description] containsString:@"Extension"]) {
return YES;
}
return NO;
}
// 方法二
- (BOOL)isThirdPartyKeyboard {
UITextInputMode *currentInputMode = [[UIApplication sharedApplication] textInputMode];
NSString *currentInputModeClass = NSStringFromClass([currentTextInputMode class]);
if ([currentInputModeClass isEqualToString:@"UIKeyboardExtensionInputMode"]) {
return YES;
}
return NO;
}