How can I identify external keyboard being accessing the UITextfields - ios

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.

Related

How hide or close my app when i reveive a call?

I have a little bug. I'm developing an iOS App.
If i receive a call, my app stays open and the screen for my entering call appears on my app. I would like to close my app if i have a call.
How can i fix that?
Thanks,
J.
The green, in-call status bar is not a bug but a feature. You don't need to close the app when the call comes.
Instead, make sure your views are resized properly when the in-call status bar appears.
As Per Apple Human Interface guidelines
Never quit an iOS app programmatically because people tend to interpret this as a crash.
However, if external circumstances prevent your app from functioning as intended, you need
to tell your users about the situation and explain what they can do about it. Depending on
how severe the app malfunction is, you have two choices.
Display an attractive screen that describes the problem and suggests a correction. A
screen provides feedback that reassures users that there’s nothing wrong with your app. It
puts users in control, letting them decide whether they want to take corrective action and
continue using your app or press the Home button and open a different app
If only some of your app's features are unavailable, display either a screen or an alert
when people use the feature. Display the alert only when people try to access the feature
that isn’t functioning. `
But again you handle your app accordingly when call comes by using the following notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(incomingCall:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callEnded:) name:CTCallStateDisconnected object:nil];
Srinivasan N's answer has the incorrect observer, you'll want to add this observer which will account for all scenarios: phone calls, Personal Hotspot, GPS/navigation, etc.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(adjustViews:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
}
- (void)adjustViews:(NSNotification *)notification
{
NSValue *rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect newFrame;
[rectValue getValue:&newFrame];
NSLog(#"Changed frame to: Width: %f, Height: %f", newFrame.size.width, newFrame.size.height);
// Adjust your views here
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

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.

Spurious UIApplicationDidBecomeActiveNotification notification

I am able to register for UIApplicationDidBecomeActiveNotification and properly receive events. But sometimes I receive these notifications WHILE the app is still running. I suspected memory problems to trigger an app resign/resume but could not confirm this was the case (I saw once a memory warning at the same time). Any reason why these methods would be called while the app is running (no call, no lock, etc.)?
I am registering for these notifications:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(appDidBecomeActiveNotif:) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(appWillResignActiveNotif:) name:UIApplicationWillResignActiveNotification object:nil];
(This is done once in a singleton constructor using dispatch_once)
The corresponding functions:
-(void)appDidBecomeActiveNotif:(NSNotification*)notif
{
NSLog(#"appDidBecomeActiveNotif called");
}
-(void)appWillResignActiveNotif:(NSNotification*)notif
{
NSLog(#"appWillResignActiveNotif called");
}
Here are some logs:
2013-04-11 09:28:11.401 App[1499:907] appWillResignActiveNotif
2013-04-11 09:28:13.505 App[1499:907] appDidBecomeActiveNotif
This is what the docs says about those notifications:
UIApplicationDidBecomeActiveNotification
Posted when the application becomes active.
An application is active when it is receiving events. An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.
UIApplicationWillResignActiveNotification
Posted when the application is no longer active and loses focus.
An application is active when it is receiving events. An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.
So, are there any overlay window pop ups or are you locking the device or anything like that?
Also, why not use the methods in the AppDelegate to listen to those events?
EDIT
The problem, it seems, is MapKit's pop up asking the user to use it's location.

Is there a delegate call when iOS keyboard language changes?

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.

Resources