UIKIT_EXTERN NSString * const UITextInputCurrentInputModeDidChangeNotification _ OSX_AVAILABLE_STARTING (_ MAC_NA ,__ IPHONE_4_2 );
This notification is available.
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (changeMode :) name: @ "UITextInputCurrentInputModeDidChangeNotification" object: nil];
Then implement the above method:
-(Void) changeMode :( NSNotification *) notification {
NSLog (@ "% @", [[UITextInputMode currentInputMode] primaryLanguage]);
}
In this way, you can get the value.
The following is the LOG result:
14:32:48. 565 UIFont [2447: 207] zh-Hans // Simplified Chinese pinyin
14:32:50. 784 UIFont [2447: 207] en-US // english
14:32:51. 344 UIFont [2447: 207] zh-Hans // simplified handwriting
14:32:51. 807 UIFont [2447: 207] zh-Hans // simplified strokes
14:32:53. 271 UIFont [2447: 207] zh-Hant // traditional handwriting
14:32:54. 062 UIFont [2447: 207] zh-Hant // traditional cangjie
14:32:54. 822 UIFont [2447: 207] zh-Hant // traditional strokes
LOG shows the language in which the user is input. However, this is sufficient for most current applications.
Direct retrieval:
[[UITextInputMode currentInputMode] primaryLanguage];
Actually, it returns a UIKeyboardInputMode class. This is a private API and not only the primaryLanguage attribute.
@ Interface UIKeyboardInputMode: UITextInputMode
{
NSString * primaryLanguage;
NSString * identifier;
NSString * softwareLayout;
NSString * hardwareLayout;
}
+ (Id) keyboardInputModeWithIdentifier :( id) arg1;
+ (Id) hardwareLayoutFromIdentifier :( id) arg1;
+ (Id) softwareLayoutFromIdentifier :( id) arg1;
+ (Id) canonicalLanguageIdentifierFromIdentifier :( id) arg1;
@ Property (retain, nonatomic) NSString * hardwareLayout; // @ synthesize hardwareLayout;
@ Property (retain, nonatomic) NSString * softwareLayout; // @ synthesize softwareLayout;
@ Property (retain, nonatomic) NSString * identifier; // @ synthesize identifier;
@ Property (retain, nonatomic) NSString * primaryLanguage; // @ synthesize primaryLanguage;
-(Void) dealloc;
-(Id) initWithIdentifier :( id) arg1;
@ End
@ Property (retain, nonatomic) NSString * hardwareLayout; // @ synthesize hardwareLayout;
@ Property (retain, nonatomic) NSString * softwareLayout; // @ synthesize softwareLayout;
@ Property (retain, nonatomic) NSString * identifier; // @ synthesize identifier;
@ Property (retain, nonatomic) NSString * primaryLanguage; // @ synthesize primaryLanguage;
Determination of these attributes
NSLog (@ "% @", [(UIKeyboardInputMode *) [UITextInputMode currentInputMode] identifier]);
It can be determined by identifier. Each type is different. You can log it and see it.
According to indentifier
UITextInputMode * inputMode = [UITextInputMode currentInputMode];
NSString * indentifier = [inputMode into mselector: NSSelectorFromString (@ "identifier")];
NSLog (@ "% @", indentifier );
// Simplified stroke zh_Hans-Wubihua @ sw = Wubihua; hw = US
// Simplified handwritten zh_Hans-HWR @ sw = HWR
// Simplified Pinyin zh_Hans-Pinyin @ sw = Pinyin; hw = US
// En_US @ hw = US; sw = QWERTY
From cloud huaikong-abel