Open standard iOS keyboard, instead of custom one - ios

I am calling becomeFirstResponder, and showing the keyboard with it.
[inputTextField becomeFirstResponder];
However, it shows the custom keyboard that is installed on test device. Is there a way to show iOS Standard Keyboard for Number Pad?

From the answer list originally at: Prevent custom keyboard in textfield
- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) {
return NO;
}
return YES;
}

Related

Sogou Custom Keyboard not firing keyboardWillShow

An app we made utilizes keyboardWillShow notifications from NSNotificationCenter
Everything was working as expected until we tried to use the app with a device that had the Sogou custom keyboard installed. When this keyboard is used (which oddly enough it doesn't seem to always come up -- for instance secure text entries ignore the Sogou keyboard) the keyboardWillShow notification is not firing.
Does anyone know of this issue or how to disable the use of custom keyboards?
The only way I found to get this to work was to disable all custom keyboards using the app delegate:
- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) {
return NO;
}
return YES;
}

re-focus UItextfield after rotation of device

I am reloading my table with reloaddata on rotation of device in my app. If a UITextfield is focused before rotation and keyboard is open , I want it to stay focused and keyboard remains open. Reloaddata calls "textfieldshouldEndEditing" and "KeyboardshouldHide" notifications and thus on rotation my textfield is not focused and keyboard is also closed.
To achieve this I am using the following code:
[myTextfield performSelector:#selector(becomeFirstResponder)
withObject:nil
afterDelay:1.0f];
This works fine and keyboard opens again after rotating the device but the problem is when I press keyboard hide button (now keyboard is closed) and then rotate the device, Keyboard is still showing up which is wrong as before rotating the device I closed it.
Can someone suggest what is wrong or what should be done to achieve this? Thanks
How about just using a BOOL class variable like this:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
hasKeyboardOpen = YES;
}
// your own method to hide keyboard you would call when user physically hide keyboard
- (void)dismissKeyboard
{
[myTextField resignFirstResponder];
hasKeyboardOpen = NO;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(hasKeybaordOpen == YES)
{
[myTextfield performSelector:#selector(becomeFirstResponder)
withObject:nil
afterDelay:1.0f];
}
}
So you before the rotation if the keyboard is visible you it and schedule it to present in 1 second.
I guess the problem is that you schedule the keyboard to present even if it is hidden. If that is the case you should check if the keyboard is visible before performSelector: withObject:afterDelay:
if ([myTextField isFirstResponder]) {
[myTextField resignFirstResponder];
[myTextField performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:1.];
}
Although I really don't think performSelector: withObject:afterDelay: is the proper way of doing it. You might want to use willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation: methods instead. You can store the reference to the textField or any other firstResponder (i.e. if you have multiple textFields or textViews:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if ([self.myTextFiled isFirstResponder]) {
self.toBeFirstResponderAfterInterfaceOrientationChange = self.myTextFiled;
[self.myTextFiled resignFirstResponder];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (self.toBeFirstResponderAfterInterfaceOrientationChange) {
[self.toBeFirstResponderAfterInterfaceOrientationChange becomeFirstResponder];
self.toBeFirstResponderAfterInterfaceOrientationChange = nil;
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
self.toBeFirstResponderAfterInterfaceOrientationChange = nil;
}

Keyboard dismissed as soon as presented

I have an app which involves using different kinds of Gestures. So, in order to differentiate between thse gestures, I used shouldRecognizeSimultaneouslyWithGestureRecognizer method which returns a YES. However, on doing this the keyboard on the UIWebView is dismissed right after it is being presented. And if I don't then the keyboard functions correctly but the controller fails to recognize different gestures.
How do I make the keyboard function correctly and at the same time recognize different gestures ?
Try this one
#pragma mark -
#pragma mark UITextFieldDelegate Methods
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
}
//You can use like this in your shouldRecognizeSimultaneouslyWithGestureRecognizer method
[textView resignFirstResponder];

Unable to update view when app goes into background in iOS 7 using applicationDidEnterBackground:

When my app goes into the background, I'm changing the view to prepare it for coming back into the foreground. In iOS 6, what I'm doing works fine. However in iOS 7, it is not working.
I'm trying to hide and show some UILabels like this:
//AppDelegate.m
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.timerVc hideTimerLabels];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self.timerVc showTimerLabels];
}
//TimerVC.m
- (void)hideTimerLabels {
for (UILabel *label in self.timerLabels) {
label.hidden = YES;
}
}
- (void)showTimerLabels {
for (UILabel *label in self.timerLabels) {
label.hidden = NO;
}
}
All of this code is firing when I set breakpoints, but doesn't seem to do anything. I've also tested the hideTimerLabels and showTimerLabels methods and they work fine in iOS 7.
It looks like this is only happening in the simulator. On an actual device with iOS 7, it works as expected. Another reminder, to test on the device more often.

Using Dictation - iOS 6 - DidStart?

How to respond to starting dictation?
Known ways of responding to dictation:
dictationRecordingDidEnd - respond to the completion of the recognition of a dictated
phrase.
dictationRecognitionFailed - respond to failed dictation recognition.
Reference: UITextInput Protocol Reference
Starting in iOS 5.1, when the user chooses dictation input on a supported device, the system automatically inserts recognized phrases into the current text view. Methods in the UITextInput protocol allow your app to respond to the completion of dictation, as described in “Using Dictation.” You can use an object of the UIDictationPhrase class to obtain a string representing a phrase a user has dictated. In the case of ambiguous dictation results, a dictation phrase object provides an array containing alternative strings.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextInput_Protocol/Reference/Reference.html
As far as I can tell, there's no public API for detecting when dictation has started.
If you really want to do it, and you want to be in the App Store, you can probably get away with the following approach, but it is totally unsupported, it might get you rejected anyway, and it is likely to break in a future version of iOS.
The text system posts some undocumented notifications after changing to or from the dictation “keyboard”. Two of them are posted both on a change to it and a change from it, with these names:
UIKeyboardCandidateCorrectionDidChangeNotification
UIKeyboardLayoutDidChangedNotification
Note that the second one has a strange verb conjugation. That is not a typo. (Well, it's not my typo.)
These notices are also posted at other times, so you can't just observe them and assume the dictation state has changed. You'll need to do more checking when you receive the notification. So, add yourself as an observer of one of those notifications. The first one seems less likely to go away or be renamed in the future.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(checkForDictationKeyboard:)
name:#"UIKeyboardCandidateCorrectionDidChangeNotification"
object:nil];
...
When you receive the notification, you'll want to see whether the dictation view is showing:
- (void)checkForDictationKeyboard:(NSNotification *)note {
if ([self isShowingDictationView]) {
NSLog(#"showing dictation view");
} else {
NSLog(#"not showing dictation view");
}
}
To see whether it's showing, check each window except your own application window. Normally, the only other window is the text system's window.
- (BOOL)isShowingDictationView {
for (UIWindow *window in [UIApplication sharedApplication].windows) {
if (window == self.window)
continue;
if (containsDictationView(window))
return YES;
}
return NO;
}
Recursively walk the view hierarchy checking for a view whose class name contains the string “DictationView”. The actual class name is UIDictationView but by not using the whole name you're less likely to be rejected from the App Store.
static BOOL containsDictationView(UIView *view) {
if (strstr(class_getName(view.class), "DictationView") != NULL)
return YES;
for (UIView *subview in view.subviews) {
if (containsDictationView(subview))
return YES;
}
return NO;
}
Although this question is answered, I still want to add my solution and wish to be helpful to someone else.
When you tap on the MIC button on the keyboard, primaryLanguage will change to dictation. You can detect that like this:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(handleCurrentInputModeDidChange:)
name:UITextInputCurrentInputModeDidChangeNotification
object:nil];
- (void) handleCurrentInputModeDidChange:(NSNotification *)notification
{
NSString *primaryLanguage = [UITextInputMode currentInputMode].primaryLanguage;
NSLog(#"current primaryLanguage is: %#", primaryLanguage);
}
UPDATE:
Just as what #user1686700 said, currentInputMode already been deprecated. This isn't a solution any more.
Please note - UITextInputMode's currentInputMode is deprecated as of iOS7.
We may just have to wait until Apple decides to publish the dictation API so we can make the calls that make sense as per our intentions.

Resources