MFMailComposeViewController Keyboard Issue - iphone

How do i dismiss the keyboard without pressing the Send or Cancel button in MFMailComposeViewController?!
Thanks for any help.

Can you try this.
UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView* firstResponder = [keyWindow performSelector:#selector(firstResponder)];
[firstResponder resignFirstResponder];
hope this helps....

I experienced a similar problem: For some reason iOS does not dismiss the Keyboard of a MFMailComposeViewController when the application enters background (the dismiss happens when the application becomes active again). However iOS dismisses the keyboard if the first responder is a simple element (e.g. textview). Calling resignFirstResponder did not work for me in this particular case.
Because I switch windows on applicationBecomeActive (to show a login screen) I ended up having multiple keyboards above each other (the one on the top not working).
I found a simple workaround to dismiss the keyboard of an MFMailComposeViewController when the application resigns active:
- (void)applicationWillResignActive:(UIApplication *)application
{
// Workaround: MFMailComposeViewController does not dismiss keyboard when application enters background
UITextView *dummyTextView = [[UITextView alloc] init];
[self.window.rootViewController.presentedViewController.view addSubview:dummyTextView];
[dummyTextView becomeFirstResponder];
[dummyTextView resignFirstResponder];
[dummyTextView removeFromSuperview];
// End of workaround
}
This will implicitly resign the first responder if we have any viewController that is currently beeing presented.

While you probably can do it by finding whichever view is the first responder and calling resignFirstResponder on it (unless you're on iPad and MFMailComposeViewController uses UIModalPresentationFormSheet), Apple might reject your app for it. Quoth the documentation:
Important: The mail composition interface itself is not customizable and must not be modified by your application.
This could easily be construed to include the behavior of the keyboard.

Related

uipopover hides when keyboard shows

i have an UIpopover with UItextfield in it, when i open popover and tap on uitextfield then keyboard shows, but it hide the popover. How can i show keyboard without hiding UIpopover?
i am calling popover in UIWebView because i use cordova 1.8.1, but i tried it in UIView too, and it hides too.
here code of calling UIpopover :
if (popEl==nil){
popEl=[[Popover alloc] init];
}
if (pcs==nil){
pcs=[[UIPopoverController alloc] initWithContentViewController:popEl];
pcs.delegate=self;
}
[pcs presentPopoverFromRect:CGRectMake(0, 0, 1, 1) inView:self.webView permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
P.S. Sorry for my English, i am from Ukraine.
firstly i recommend you to go through the apple documentation of UIPopOverController
for your problem i think you have to deal with the appearance and disappearance of Keyboard here's the solution to handle this problem Check it
Your question is that, when U click on the textField the pop over view should appear,right? if yes, then add this code before you add the popoverview,
[textField resignFirstResponder];

Weird keyboard behavior in my iOS app

Ok, so here's how my keyboard behaves:
There's a button which calls a method to send a textmessage, that works fine. If the user now sends the text everything's fine.
Now if (s)he taps cancel it switches back to my view (as it's supposed to do), but the keyboard won't show up. I already tried
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
[self dismissModalViewControllerAnimated:YES];
[inputView becomeFirstResponder];
}
since it didn't work I tried:
-(void)viewDidAppear:(BOOL)animated{
[inputView becomeFirstResponder];
}
but that won't work either. So how can I get my keyboard to show up?
EDIT: inputText is an UITextView.
This might be related to sending YES in dismissModalViewControllerAnimated:. When animations are involved, statements generally don't remain synchronous. So, your call to [inputView becomeFirstResponder] must be executing before the modal dialog has been dismissed, resulting in an inconsistent state. This is the reason why the inputView does not take focus.
HTH,
Akshay

iPhone app entering back into foreground shifts the view back to its origins and keyboard is still visible

I'm currently working on an iPhone 4 app with a registration view. The users can focus into a UITextField and I have code that will shift the view upwards to prevent the keyboard from covering up the textfield. But if the app is backgrounded and brought back into the foreground again, the keyboard is still up, the textfield is still in focus, but the view is now shifted back down in its original state. This covers up the textfield.
What's going on? How do I either make the view stay put or hide the keyboard when the app is brought back into the foreground?
UPDATE:
-Any changes for this on the new iOS5?
you could try doing something in applicationDidEnterBackground in your app delegate like
NSLog(#"%#", [self.viewController.YOURTEXTFIELD isFirstResponder]);
if ([self.viewController.YOURTEXTFIELD isFirstResponder]) {
[self.viewController.YOURTEXTFIELD resignFirstResponder];
}
the "isFirstResponder" checks to see if the keyboard is currently being used in this view and returns YES if it is and NO if it isn't.
The NSLog is there just so you know what is getting passed into the if statement.
I've next solution:
In AppDelegate
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// 1. get access to ViewController which is on top
// In my case, I have navigation controller in root
UIViewController* current_controller = [self.rootNavController.viewControllers lastObject];
// 2. loop all uitextfield.
for (UITextField* o_txt in [current_controller.view subviews]) {
[o_txt resignFirstResponder];
}
}
Look's like "hot fix" )

Keyboard won't dismiss when popover closes on iOS 3.2

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
[self dismissFirstResponder];
return YES;
}
-(void)dismissFirstResponder {
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];
}
I have tried loads of different things, but the keyboard just isn't going down:
I checked to see if my outlets were hooked up correctly in Interface Builder
I put breakpoints inside the 2 methods to check they were being called at the appropriate times, and they were. Those 3 Text Fields are the only ones in the app.
What happens: The popover gets dismissed but the keyboard stays up.
I would really appreciate some help on this matter. It might be a known bug on iOS 3.2, if so any workarounds would be gratefully accepted. Thanks
Make sure the delegate for UITextView the UITextField is assigned
Then call the following method to dismiss any keyboard activity from the view.
[self.view endEditing:YES];

Show iPhone soft keyboard even though a hardware keyboard is connected

My iPad app uses an external "device" that acts as a hardware keyboard. But, at some point in the settings, I need to input text and I can't use the "device" ("device" is not a keyboard).
So, is there any way to force pop the soft keyboard even thought I have a hardware keyboard connected?
Yes. We've done this in a few of our apps for when the user has a Bluetooth scanner "keyboard" paired with the device. What you can do is make sure your textField has an inputAccessoryView and then force the frame of the inputAccessoryView yourself. This will cause the keyboard to display on screen.
We added the following two functions to our AppDelegate. The 'inputAccessoryView' variable is a UIView* we have declared in our app delegate:
//This function responds to all textFieldBegan editing
// we need to add an accessory view and use that to force the keyboards frame
// this way the keyboard appears when the scanner is attached
-(void) textFieldBegan: (NSNotification *) theNotification
{
UITextField *theTextField = [theNotification object];
// NSLog(#"textFieldBegan: %#", theTextField);
if (!inputAccessoryView) {
inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, navigationController.view.frame.size.width, 1)];
}
theTextField.inputAccessoryView = inputAccessoryView;
[self performSelector:#selector(forceKeyboard) withObject:nil afterDelay:0];
}
//Change the inputAccessoryView frame - this is correct for portrait, use a different
// frame for landscape
-(void) forceKeyboard
{
inputAccessoryView.superview.frame = CGRectMake(0, 759, 768, 265);
}
Then in our applicationDidFinishLaunching we added this notification observer so we would get an event anytime a text field began editing
//Setup the textFieldNotifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(textFieldBegan:) name:UITextFieldTextDidBeginEditingNotification object:nil];
Hope that helps!
There’s no way to do this with the current SDK. Please let Apple know via the Bug Reporter.
The solutions here didn't work on iOS 13 or aren't App Store compatible so I solved the problem by creating my own soft keyboard. It is pretty basic but works. Feel free to contribute!
Project on Github
All you have to do is add SoftKeyboardView.swift to your project and somewhere (e.g. appDidFinishLaunching) hit the singleton:
Usage:
SoftKeyboardManager.shared.disabled = false
Since I have the same problem, the closest solution I have found is to use Erica Sadun's app called KeysPlease which is available via cydia and modmyi. It's description is "Use soft kb even when connected to a BT kb.".
Additionally I have found that if you have a physical keyboard also attached, in my case via the iPad keyboard doc, you can bring up the keyboard using a key which seems to map to the eject key on a bluetooth keyboard. Perhaps there is a way to inject this key as if it was pressed on an attached keyboard?
I really wish there was a more official coding solution to this.
When my app connect bluetooth device, keyboard wouldn't show.I try set force the frame of the inputAccessoryView as Brian Robbins say. It didn't work.
Then I use a stupid way to solve.I found when I click textfield or textview one more time, keyboard will show.
So I just need to simulate touch in textfield or textview once , it works.
If you want to do some simulate touch, check this.
https://github.com/HUYU2048/PTFakeTouch