App crashing in iOS 11.3 with error object cannot be nil (key: UIAutofillContextDelegateKey)

I have a web based application that needs to check the current textInputMode. In earlier iOS versions code was working properly, but the same code has start crashing in iOS 11.3 . The app crashes if list of keyboards added in Settings does not conatin "en-US" or "en-GB".


//observer added on keyboard actions

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(inputModeDidChange:)

name:UITextInputCurrentInputModeDidChangeNotification

object:nil];



//Below method implemented to check current text input mode

-(void)inputModeDidChange:(NSNotification *)notification {

NSString *inputMethod = [[UITextInputMode currentInputMode] primaryLanguage];

//NSString *inputMethod = [UIApplication sharedApplication].delegate.window.textInputMode.primaryLanguage;

NSLog(@"inputMethod=%@",inputMethod);


if (!([inputMethod isEqualToString:@"en-GB"] || [inputMethod isEqualToString:@"en-US"])) {


UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Application supports English (US) and English (UK) keyboard only." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

[alert show];

}

}


I am aware that currentInputMode is deprecated since iOS 7.0 : [[UITextInputMode currentInputMode] primaryLanguage];

So tried with -> NSString *inputMethod = [UIApplication sharedApplication].delegate.window.textInputMode.primaryLanguage;

But it didn't work.

The error message is as below :

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: UIAutofillContextDelegateKey)'

But there is no explicit call to set value for UIAutofillContextDelegateKey anywhere in code


Can somebody help me?

App crashing in iOS 11.3 with error object cannot be nil (key: UIAutofillContextDelegateKey)
 
 
Q