3

A new API has been added in iOS 10 to present the list of other keyboards the user can switch to - the same list that appears when users long press the globe on a system keyboard. The declaration of the function is as follows:
func handleInputModeList(from view: UIView, with event: UIEvent)

My question is, what's the proper way to generate a UIEvent to supply? I was planning to call this function using a UILongPressGestureRecognizer but this API doesn't reveal UIEvents.

Jordan H
  • 52,571
  • 37
  • 201
  • 351

1 Answers1

6

I was going about this the wrong way. No need for custom gesture handling. As noted in the headers, one should add a target-action to the control they want to trigger this, like so:

Objective-C:
[keyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];

Swift:
keyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: UIControlEvents.allTouchEvents)

Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • 3
    If I do this, my keyboard crashes with an SIGQUIT error. I'm going to stick to creating an action for my nextKeyboardButton and call advanceToNextInputMode() when it is pressed. – Jack Robson Feb 12 '17 at 12:02