Maple
Maple

Reputation: 741

Dismiss keyboard opened by the sharing app when in Share Extension without text input fields

After selecting text in a textview/textfield in an app (Messages, for example), you can select Share from the popup menu to share the text. Since you were editing text at the time you selected/shared, the keyboard is visible. Once you have selected an share target app, the keyboard will continue to be visible when the target app's extension appears. I need to dismiss this keyboard so that other elements on the screen are visible and accessible. In my case, I have no editable fields (e.g. textField/textView) in the custom view controller that appears in the extension. (i.e. to become firstResponder)

The usual solutions that do not work:

  1. Use the Dismiss button in the KB - does not exist on iPhone
  2. [self.view endEditing:YES] - No subview in my view is firstResponder
  3. [self.textView resignFirstResponder] - No textView/textField in my view (https://stackoverflow.com/a/28119785/650365)
  4. [[[UIApplication sharedApplication] keyWindow] endEditing:YES] - sharedApplication is unavailable in share extensions
  5. [theViewController setEditing:NO animated:YES]

Hacky solution that does work (from https://stackoverflow.com/a/34299724/650365):

How can I dismiss the keyboard in a Share Extension on iPhone without adding extra textField/textViews?

Upvotes: 1

Views: 659

Answers (1)

regina_fallangi
regina_fallangi

Reputation: 2198

Your ShareViewController inherits from SLComposeServiceViewController. That is what causes the keyboard to be presented, it has a textView.

Replace that SLComposeServiceViewController with a simple UIViewController and the keyboard will not appear.

Upvotes: 0

Related Questions