I have created my own custom keyboard and I want to show list of keyboards view as Apple does. How can I reach this?
Yes it's possible since iOS 10
If you have an UIButton called nextKeyboardButton just add that in your viewDidLoad function.
nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)
handleInputModeList is part of UIInputViewController
This is not possible.
Apple documentation for developing custom keyboards says (emphasis mine):
To ask the system to switch to another keyboard, call the
advanceToNextInputMode method of the UIInputViewController class. The
system picks the appropriate “next” keyboard; there is no API to
obtain a list of enabled keyboards or for picking a particular
keyboard to switch to.
Note that you must provide a way to get to the next keyboard using the above method.
Related
I'm worked on a custom keyboard and Apple review team rejected it because the keyboard does not support 'Numbers and Decimals' types.
So, I found that the problem is that when a text field requires those specific type of keyboard (for example to inset age, measures, or other numeric values), my keyboard 'misses to respond'.
I understood, reading from Apple documentation, that you must respond to the UIKeyboardTpye property per text object's.
I searched for specific delegate of the UIInputViewController but I wasn't able to find something close to that.
In this forum I found that one good place to examine the current keyboard type required is the textDidChange: delegate, but, it is not called.
I suppose this responder is called when your keyboard, somehow, 'declares' to iOS that it can handle Numbers or Decimal types. In fact I created a simple app with a simple UITextView that requires the Decimal keyboard type:
textView.keyboardType = UIKeyboardTypeDecimalPad;
And I put a NSLog() in the keyboard extension Input View Controller textDidChange: delegate.
As I tap on the text view my delegate is not called, instead the standard Decimal keypad is shown and in the Xcode console I see the following message:
Can't find keyplane that supports type 8 for keyboard iPhone-Portrait-DecimalPad; using 405786210_Portrait_iPhone-Simple-Pad_Default
I noticed also that this message comes when the UITextView requires the not-allowed keyboard types, i.e. the phonepad. All other keyboard types do not issue that message and the custom keyboard is shown and the textDidChange: delegate is correctly called.
The Numbers and Decimal types are surely allowed and are a MUST for the review team guys. Why the behave as a forbidden-types?
I think we need to 'declare', for example in the info.plist that our extension supports various keyboard types, but... well or more simply... I do not get the point... so... I'm asking... How can I add multiple keyboard types to my keyboard extension??
Thank you very much for help!
After the second rejection of my keyboard extension they sent me a screenshot. I noticed that they, generally, test apps on iPad. This made me think.
After some test it came out that the Numbers and Decimal types do not respond the same way on iPhone and iPad.
On iPhone a text view requiring Numbers or Decimal type keyboard always shows the iOS keypad, i.e. the custom extension is not called.
On the other side, on the iPad a text view requiring Numbers or Decimal type keyboard activates the custom extension.
Finally, after provided a standard numeric keypad (even if my keyboard uses hand-written techniquies) it was approved.
Is there any way to programmatically detect installed keyboards and/or change the keyboard to a custom keyboard from within your app? As in, if I wanted to show a toolbar above the text keyboard with shortcut buttons to commonly-installed custom keyboards, could I a) detect the keyboard is installed, and b) change to a given keyboard on tap?
This assumes you want the list of keyboards setup in the Settings app under General, Keyboards.
You can determine the primary keyboard:
UITextInputMode *currentMode = [[UITextInputMode activeInputModes] firstObject];
You can determine the possible keyboards
NSArray *possibleModes = [UITextInputMode activeInputModes];
You can determine when the keyboard changes. This is done by listening for the UITextInputCurrentInputModeDidChangeNotification notification.
However, there is no API to change the keyboard.
So you can do everything you need except the most important part.
I'm currently experiencing either a bug or lack of understanding of Apple's Documentation.
Some background. I'm using AVPlayer to initiate a playback of audio. I'm using AVPlayer because it provides more precise controls over playback positioning (dropping into specific spots of a song).
When I implement the code below, the MPRemoteCommandCenter only displays one button (the play/pause button) and all other buttons (back and forward) are not present.
MPRemoteCommandCenter.sharedCommandCenter().playCommand.addTarget(self, action: "remoteCommandMute")
MPRemoteCommandCenter.sharedCommandCenter().pauseCommand.addTarget(self, action: "remoteCommandMute")
I can then toggle whether it's disabled or not just fine. According to Apple's documentation however you should be able to toggle the enabled property and it should hide the buttons entirely without having to add a target to them (at least from my understanding). Here is the reference to the documentation
If I do not include the .addTarget code to any of the buttons and simply follow the instructions from apple to disable said buttons, it does not work.
MPRemoteCommandCenter.sharedCommandCenter().previousTrackCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().nextTrackCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().playCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().pauseCommand.enabled = false
Based on this behavior I would expect that disabling all three buttons would in turn make them hidden however this is not the behavior at all in fact disabling them has no effect on them. You can still press them and they behave as if that code isn't present at all. However, if (as stated above) I add the .addTarget to the button it will become disabled if I set the .enabled flag to false.
Please correct my logic/understanding if this isn't the intended behavior but in my opinion this is absolutely backwards thinking on Apple's part. If my app doesn't support pausing forward or backward functionality the button shouldn't appear at all and disabling it shouldn't just turn it grey (like it currently does). It also shouldn't magically hide buttons if you don't add a target to them either.
On a side note, whenever I do add a target to the buttons they work just fine even if I don't want my app to have the forward and back capabilities.
So after experimenting with the different available button types and actions, it seems that the wording in the documentation could be better. In order to "disable and hide" a button one simply needs to add a target to the desired button. For example, likeCommand.addTarget disables the previous pause/play and forward buttons and hides them. However, if I set the playCommand.enabled to false, it will display said button as greyed out.
Edit: To address not actually sharing the code to which I'm referring...
import UIKit
import PlaygroundSupport
import MediaPlayer
class MyViewController : UIViewController {
private let remote: MPRemoteCommandCenter = MPRemoteCommandCenter.shared()
override func loadView() {
remote.playCommand.addTarget(self, action: #selector(playPause))
remote.playCommand.isEnabled = false
}
#objc private func playPause() {
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
This demonstrates the issue outlined such that toggling the isEnabled property does not do like the documentation states
iOS 8 lets us create our own custom keyboards.
Is it possible to make a custom keyboard output anything other than unattributed NSStrings?
Can I make a keyboard that outputs images to say the Messages app, or is it impossible?
No, this would be too difficult since most UITextField / UITextView can only handle NSString object.
As described in the UITextDocumentProxy only NSStrings are allowed.
UITextDocumentProxy is the communication object used by UIInputViewController. UIInputViewController seems to be the base for creating custom keyboards.
Also have a look at App Extension Programming Guide
- Custom Keyboard
You can create a twitter-style workaround: when the user selects an image, you upload it to your server and send a shortened url in reponse. this shortened url will be inserted to the text view of the host app and good luck :)
I have a requirement wherein I have to change the text of the return key of the iPad to Sign-in. Obviously it is not one of the options available in the sdk. I have searched it over the net and it seems doing that possible.
The only question remaining is whether the app would be accepted by Apple if I modify the default system keyboard? The HIG is not clear on this , it states that "A custom input view can replace the system-provided onscreen keyboard in apps" and "You can also provide a custom input accessory view, which is a separate view that appears above the keyboard (or your custom input view)". Nothing about whether we are allowed to add an extra button on a system keyboard.
Any experiences??
#Vin you can change the name of return key of the keyboard to your requirement. I have an app that has the changed to return key name to Done and Search. And apple did not reject it.
To "Sign-In" you can use the return key UIReturnKeyJoin
textField.returnKeyType = UIReturnKeyJoin;
EDIT
Nope. You get the return key and
keyboard types defined in the OS.
Unless you want to try to hack the
keyboard's view hierarchy to change
that button, which would be a really
bad plan. (Standard recommendation
here is to file a bug report with
Apple to let them know you'd like
more/different options.)
see Custom iPhone return key text
Since I didn't get any satisfactory answer, I convinced the client that it would be inappropriate to modify the default system keyboard for a sake of one button(even if it is allowed by Apple). We are now going for the "Go" option available for return key.