Is there a delegate call when iOS keyboard language changes? - ios

I have a scenario where I'd like to have a handler that gets triggered when the user presses the language change(globe icon) on the keyboard for iOS.
How I may achieve that?
Thanks

The following should work:
You would have to use a UIKeyboard notification within your code
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
Then within your keyboardWillBeHidden: or similarly named method use the answer (link below) which returns you a two letter code for the currently selected language.
Link: Getting current device language in iOS?
So your method keyboardWillBeHidden: method is called when the keyboard is hidden reads from the system the keyboard language option that is currently selected.
Thats the theory, I haven't tried this myself, good luck.

Related

How to detect external keyboard plugged or not for iPad?

I want to programmatically detect whether an external keyboard connected or virtual keyboard is visible on given view. How can I do it?
I could do it using Keyboard notifications but I need a different way to do it. Is there any other way to do it?
Maybe this helps...
First Register Notification :
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
Then Recieve :
-(void)keyboardWillHide:(NSNotification *)_notification {
NSLog(#"%#",[_notification infoDict]);
}
-(void)keyboardWillShow:(NSNotification *)_notification {
NSLog(#"%#",[_notification infoDict]);
}
This will be called just when inside keyboard will be showned and no external keyboard is attached ! If external keyboard is attached WillShow Notification won't be called .
Source:
How to detect external keyboard connectification in objective-c?
Another way could be:
An indirect and SDK-safe way is to make a text field a first responder. If the external keyboard is present, the UIKeyboardWillShowNotification local notification shall not be posted.
You can listen to the "GSEventHardwareKeyboardAttached" (kGSEventHardwareKeyboardAvailabilityChangedNotification) Darwin notification, but this is a private API, so it's possible your app will get rejected if you use this. To check if the external hardware is present, use the private GSEventIsHardwareKeyboardAttached() function.
UIKit listens to this and sets the UIKeyboardImpl.isInHardwareKeyboardMode property accordingly, but again this is private API.
Source: How can I detect if an external keyboard is present on an iPad?

Keep ios keyboard open

I have a ios app that launch a UIWebView and you can interact with this web (the app is like a container). In the interaction with the web you need the keyboard a lot. So, I want (if it's possible) to keep the keyboard always open.
I've found some solutions, but none of them work for me.
I've tried with:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
and I able to detect when the keyboard are going to hide, but I don't know what I can do in keyboardDidHide method to avoid the keyboard to be closed.
I've tried also with:
webView.keyboardDisplayRequiresUserAction
But nothing happens.
Do you know how I can do this?
Thanks!
You can try playing with UIViewController's disablesAutomaticKeyboardDismissal property. Try overriding this property and returning NO.

How can I identify external keyboard being accessing the UITextfields

In my iOS application I am using accessory view as well I am shifting the view when keyboard is launching. But when i am using external keyboard (Bluetooth device) i do not need to show accessory view as well view shifting I need to avoid for that use case.
Is there any delegate which can identify the precedence i.e either virtual keyboard will be launched or external keyboard is activated.
Thanks in advance
Kirti
When keyboard will appear keyboardWillShow will be broadcasted on using UIKeyboardWillShowNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification
object:nil];
If you are using any bluetooth keyboard then this notification will not be broadcasted.So if you use this to adjust views for the software keyboard, you should handle that based on this notification.
Otherwise you can check the keyboard size differences in the userInfo property of the notification.
Hope it helps you.

How to determine when a user has copied text

I am having a hard time how to figure out when a user has selected & copied text the default iOS way:
canPerformSelector works before presenting this menu, but I am interested in knowing after the user has pressed the copy button.
Thank You
Use NSNotification as observer for UIPasteboardChangedNotification: then every time user copies it will call a method which you specified in Notification observer
Something like this
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ClipBoardChanged) name:UIPasteboardChangedNotification object:nil];
-(void)ClipBoardChanged{
NSLog(#"ClipBoard data changed %#",[UIPasteboard generalPasteboard].string);
}

iOS how to catch event of switching standard keyboard type to number keypad?

When switching to number keypad, I want to use my custom number keypad.
How to realize this function?
Apple don't give any APIs about this?
Thank you.
there is a notification for change in UITextInputMode class
UITextInputCurrentInputModeDidChangeNotification
so add this notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardModeChange:) name:UITextInputCurrentInputModeDidChangeNotification object:nil];
i hope it should work for u. happy coding :)

Resources