How to detect the Smart/external Keyboard on iPad? - ios

How can one get a notification when a (Smart) keyboard is connected?
Some context:
I am working on a feature that automatically shows and hides my software keyboard based on whether the iPad Pro Smart Keyboard, or another external keyboard is connected or not (like Pages). I have seen this answer but that only applies when a textfield is selected. After a lot of googling, I stumbled into the Apple's ExternalAccessory class which you can ask for connected devices, and then check what these devices are.
I have tried a basic implementation of this and I can't get it to work on my iPad Pro with connected Smart Keyboard (Yes, I am sure it's connected because I can see the letters I type appear on my screen 😅).
First of all, the docs say that you can detect devices that are through over Bluetooth and Lightning, I can only to hope this also includes the Smart Keyboard connector. I have enabled the Wireless Accessory Configuration capability of my project.
Second, one needs to add the UISupportedExternalAccessoryProtocols key to their info.plist, then needs to specify which protocols are connected. Which protocols there are doesn't seem to be documented, also not for Apple's own devices. I ran into a tutorial that mentioned the iAP2 bluetooth protocol, so I added this and then hoped for the best.
My code
As I haven't set up my project configuration right yet, I didn't add a lot of code either. I tried:
func printAllAccessories() {
for device in EAAccessoryManager.shared().connectedAccessories {
print("connected device with name: ", device.name)
}
}
But noting seems to be connected.
Bottom line
What is the process, including project configuration, to get external keyboard notifications in an iOS App?
There doesn't seem to be any comprehensive documentation of this online so it's probably nice to get that here. Any help would be highly appreciated!

First of all this doesn't work because smart connector is not using bluetooth to connect to device. You can read more about that on this page Use your Smart Keyboard Folio or Smart Keyboard with iPad Pro.
Second thing is that apple Smart Keyboard and external keyboard is totally different thing. Apple Smart Keyboard can be used as iPad case and as iPad keyboard. External keyboard is used only as keyboard and nothing else.
So from this we can conclude that when you connect you Smart Keyboard to iPad with Smart Connector iPad will treat it as iPad case, which gives you protection for your iPad and no other functionality which would impact on your software(try to type on it or use any shortcuts, nothing will work). iPad will recognise Smart Keyboard as keyboard only when it will be folded in type position. This is the main difference from external keyboard. External keyboard will be recognised as soon as you connect it via bluetooth.
Pages app will hide keyboard only if the external keyboard is connected via bluetooth or your Smart Keyboard is in type position. If Smart Keyboard is connected to Smart Connector and is not in type position there will still be software keyboard until you fold it in to type position. This means that iOS will handle hiding and showing keyboard.
For handling key presses performed on hardware keyboard you can refer to this class UIKeyCommand.

Related

How to enable virtual/soft keyboard while connected to a Bluetooth keyboard/Barcode Scanner for React Native on iOS?

I've been researching for quite a while and none of the solutions seemed viable enough. For example: articles as referred within Force software keyboard on iOS 10
Our bluetooth bar code scanner has a button which brings up/down the soft/virtual keyboard, but that's definitely not as user-friendly as having a keyboard popping up when focusing on text input.
Is there anyway to accomodate both virtual/soft keyboard and bluetooth keyboard input on iOS? Thanks!
We've also looked into this which seems promising, display soft keyboard (iPad) when is connected a bluetooth input device
but it requires importing of private framework which isn't supported on newer XCode's, and isn't App Store-Ready?

iOS - How to make custom keyboard extension work with physical keyboard

I have had this question for a long time and I tried to search it in iOS 10 APIs but I couldn't find any, if anyone knows the corresponding APIs, please help here.
So I have an iOS custom keyboard for Mandarin and it requires selecting word after some inputs.
Google's custom keyboard GBoard now supports Simplified Chinese and it works with iPad Pro Smart Keyboard and it will display a list of candidate words right below the cursor as shown in this video.
GBoard Simplified Chinese Input
But I couldn't find the corresponding API to make this happen for my own custom keyboard extension.
So 2 questions here:
Is it doable now to make a custom keyboard extension work for external physical bluetooth keyboard, and how? Not iPad Pro Smart Keyboard but generally using Apple bluetooth keyboard with say an iPad Air.
If #1 it not doable now, how can I make my custom keyboard work like GBoard so that when the user types some english chars, the candidate list will appear right below the cursor and then use arrow keys to navigate and enter to input.
Much appreciated.

Would a physical keyboard prevent a inputAccessoryView from appearing?

I've added an inputAccessoryView to the iOS keyboard for certain UITextFields in my app. This accessory view provides essential functionality to the user (some buttons that are displayed nowhere else in my app). My understanding (which could be completely wrong) is that if a physical (bluetooth) keyboard is available iOS will not clutter the screen with the software keyboard. If that's the case, users of my app with a physical keyboard will be missing some functionality and I'll need to account for that. So the first question is, is that something I have to worry about? Thanks.
The input accessory view should appear at the bottom of the screen if a physical keyboard is used, so they will still be able to access the functionality. If you want to try this in the simulator, check the Simulate Hardware Keyboard option under the Hardware menu.

bluetooth keyboard override

Is there a way to force up a software keyboard when the user has a iOS bluetooth keyboard device installed?
Or, to that end, is it possible in code to disable a specific bluetooth device?
Thanks!
In most (maybe all?) iOS apps with which I have used Apple's bluetooth keyboard, pressing the eject key (located in the top right corner) will bring up the soft keyboard on the screen. Maybe that little factoid could help you in some way.
Not from within the application's code, if you're planning on getting into the app store. Apple expressly does not provide methods to show or hide keyboard, instead pushing you to use becomeFirstResponder and resignFirstResponder.
You may be able to do this through some non-AppStore-friendly methods, but somehow I don't think that's the answer you're looking for.
(Note - you could make a fake, Apple-looking keyboard when the real one is hidden, and check if the real one is hidden based on whether a view is visible, but if Apple notices you doing this, you'll get denied.)

How to display virtual keyboard when a physical keyboard is connected

Is there a way to programmatically force the virtual keyboard to appear when there is a bluetooth keyboard connected to the iPad?
I have a bluetooth barcode scanner connected to the iPad, which acts as HID (keyboard). The problem is, the virtual keyboard stays hidden in my app. Is there any way I could force the virtual keyboard to show without using any unofficial SDK calls?
Darn I was hoping someone would be able to answer this question! Goran have you been able to find anything since July?
I have one idea, although I'm not sure whether it works or not... Apparently the Apple bluetooth keyboard has a shortcut that opens the virtual keyboard. If, using javascript, you can send this command to the iPad, the virtual keyboard will open?? Is this possible?

Resources