UITextInputMode currentInputMode is deprecated. 警告的解决

- (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);
}


如果你的工程最低支持版本为7.0 你会发现有警告 : 'currentInputMode' is deprecated: first deprecated in iOS 7.0 


替换方案:

UITextInputMode *currentInputMode = [notification object];
或者

UITextView *textView = [[UITextView alloc] init]; UITextInputMode *currentInputMode = textView.textInputMode;

你可能感兴趣的:(UITextInputMode currentInputMode is deprecated. 警告的解决)