Change Keyboard in XCUITest/Simulator - swift

I want to change the keyboard language programatically for my XCUITests to try various different keyboards. I've tried:
XCUIApplication().launchArguments += ["-AppleLanguages", "(fr)"]
XCUIApplication().launchArguments += ["-AppleLocale", "fr_FR"]
But this only changes language and locale, but it still keeps simulator default keyboard. I know I could probably do it by going to the settings app (inside of the UITest) and just change keyboard, but I'd like to do it as an input argument or similar.
I also don't want to have all keyboard languages installed on the simulator at the same time, only the one language I choose.
How can I accomplish this?

Since you do it in Simulator, you can access the entire macOS disk space, including Simulator support files.
Each simulator has its own setting located in
$HOME/Developer/CoreSimulator/Devices/SIMULATOR_ID/data/Library/Preferences/.GlobalPreferences.plist
In this file, you can change AppleKeyboards programmatically.

New path for .plist file to change properties of keyboard from Roman Zakharov's answer:
/Users/YOUR_USER/Library/Developer/CoreSimulator/Devices/YOUR_SIMULATOR_ID/data/Library/Preferences/com.apple.keyboard.preferences.plist
Simulator ID can be found from Xcode: Window -> Devices and Simulators -> Simulators. The Identifier value is the UDID.

Related

Is there a way to set the find options in Xcode9 via keyboard?

If you want to search for something in Xcode9, ⌘F opens the find bar, ⇧⌘F opens Find in Project in the Navigator.
However, I often want to switch between contains, matches and regex, but the dropdowns (see image) to set this are not reachable via keyboard, only mouse.
For Xcode7, there seemed to be a way (see here), but this doesn't work any more.
Does anyone know how to set these options via keyboard in Xcode9?
In macOS System Preferences -> Keyboard -> Shortcuts, you have to set Full Keyboard Access to All Controls.
After that you can Tab to all the options.
This has worked for Find in Project (⇧⌘F) since Xcode 9.0. For the "normal" find (⌘F) it was buggy util apple fixed it in Xcode 9.3.
Resolved Issues
The source editor find and replace control now
supports Full Keyboard Access. (33666790)

iOS 6: Turn off keyboard shortcuts

Is there is any way to turn off keyboard shortcuts in iOS 6 for particular textfield/textview?
I want to turn off keyboard shortcut for my app only and not from 'Settings app' of iOS.
I started writing my own text editor to achieve it.
You could try turning off autocorrection for your text field or text view with its autocorrectionType property—if the shortcut functionality is included in that (which seems likely), then it should get disabled as well. I’m pretty sure there’s no way to control the shortcut system itself; you might consider filing an enhancement request for it.
There is no standard way to turn off keyboard shortcuts on application level (For non jailbroken iOS).
To achieve this I stated with implementation of custom TextView with Core Text and UITextInput protocol.
Add #property for keyBoardShortCuts,
Override "tokenizer" getter method by following way to turn off shortcuts.
- (id <UITextInputTokenizer>)tokenizer {
if(self.keyBoardShortCuts)
return _tokenizer;
else
return nil;
}
If we remove tokenizer, there is be no keyboard shortcuts in custom view, even though shortcut are turned on from iOS setting.
Note: Take care of one thing, as we are not depending on tokenizer, now, in this case, use enumerateSubstringsInRange:range options:NSStringEnumerationByWords/Lines block to find out selection range for word or line.
To try this add above code in EGOTextView project to turn off default shortcuts.
From what I know, if you iphone is not jailbroken then you cannot turn it off for particular apps. It is more like a "master setting" that if changed, change applies to everything within iOS.
If it jailbroken, i know there are utility apps you can download that allow you to tweak the OS in that fashion...
Settings > General > Shortcuts. There are ready-made ones and any that you may have set up. They apply across all your iOS devices including your desktop Mac.

iPhone - System strings not localized on device

I build a project using XCode 4 and I was running on the simulator since now. I had noticed that the strings in System type "Edit" and "Save" buttons where in english, but everything in my simulator was set to french. I suspected a bug like the one I had in XCode 3.
But now I'm running on my pure french configured iPhone, and those buttons are still in english, and are not localised as in other apps I can use.
I noticed that in my info.plist, the "Localization native development region" was set to "en" by default. I've changed this to "Fr" or "France" in the drop down menu, but that does not chage anything.
How may I correct this to make those buttons show a localized title ?
I had basically the same question, but Black Frog's answer didn't really help me. I did some research and this is what I found out:
The localization is primarily based on the bundle. With info.plist you can add localizations that aren't in the bundle, but you can't remove localizations that are present in the bundle.
The preferred way to add a French localization in Xcode 4 is to do the following:
Open project in Xcode >= 4.0.2
Click on project file
Select item under Project title on the right
Check Localizations table.
Select the localization you want to duplicate (English)
Click + and select the language you want you're app to use (French)
If you don't wan't to support English there are two additional steps:
Select the localization you want to remove (English)
Click - and delete the files
Special thanks to Nekto who helped me figure this out.
You have to create localized version of your nib files. Or you can set the text of each button/label to a localized string in view load.

How do I type using my keyboard on the iphone simulator?

I used to be able to type with my real mac keyboard after launching the iPhone Simulator. Typing with the on-screen simulator keyboard is just horrible when testing with large amounts of text.
No matter what I do, I can't get my keyboard to type anymore inside the simulator. Even if I have "Simulate Hardware Keyboard" switched ON, it just won't type anything. Can someone please tell me what I'm doing wrong? Is there no way to type using the real keyboard anymore?
Try trashing the iPhone Simulator preferences file. When my iPhone Simulator stopped responding to keystrokes, this fixed it.
Quit the simulator.
Go to finder and press (command+shift+G) then navigate ~/Library/Preferences.
Move com.apple.iphonesimulator.plist to the trash.
Try launching your iPhone app in the simulator again.
Deleting com.apple.iphonesimulator.plist did not help me under Xcode 6.0.1.
Probably, it worked in old Xcode.
But, what works perfectly for me under Xcode 6.0.1, it is new hot Keys in iOS Simulator:
Shift-Command-K Connect/Disconnect Hardware Keyboard
Command-K Toggle (Show/Hide) Software Keyboard
And, you know, I really suffered for last 2 months, until found it, and it is very convenient now))
Don't trash the iPhone simulator preference files. There's no need to do this.
Look in the simulator's menu Hardware ➔ Keyboard. The menu options are:
iOS Uses Same Layout as OS X
Connect Hardware Keyboard ⇧⌘K
Toggle Software Keyboard ⌘K
Ensure option 2 is checked.
If it's already checked, uncheck it then check it again (you'll probably want to learn the keyboard shortcuts).
If you find that this hides the on screen keyboard, but you also want this to show, use option 3 to toggle it back on.
If rotating the simulator seems to stop the keyboard working, toggle option two off then back on – this seems to resolve it.
I am using iOS Simulator Version 7.0. While the simulator was running I went to iOS Simulator->Reset Contents and Settings... and reset the simulator from there. That seemed to have done the trick for me. Hope that helps.
This is because you have used changing the orientation of simulator using keyboard shortcuts. Just press cmd on the mac keyboard then start typing.
All I needed to do was quit the simulator and launch it again
MY PROBLEM WAS KEYBOARD IS SHOWING AND KEYSTROKES NOT DETECTING. AND I FOUND THE SOLUTION:
You don't need to quit the keyboard.
Try Hardware->Keyboard->Connect Hardware Keyboard directly
Removing com.apple.iphonesimulator.plist worked for me too, but I had to locate it inside the hidden folder /Users/[yourusername]/Library/Preferences/
Shell / Command-Line / Jenkins / CI:
sh "plutil -replace DevicePreferences.${deviceID}.ConnectHardwareKeyboard -bool NO $HOME/Library/Preferences/com.apple.iphonesimulator.plist"
sh "plutil -extract DevicePreferences.${deviceID} xml1 -o - $HOME/Library/Preferences/com.apple.iphonesimulator.plist"
The Device ID can be found via xcrun / simctl, based on the devoce name:
xcrun simctl list | grep ${simulatorDeviceName} | sed 's/).*(.*//;s/.*(//'
I encountered the same problem and tried a lot of different ways which worked mostly but never for sure. Ultimately, I found this. https://stackoverflow.com/a/26057011/1463604
If you are developing a React Native app and you cannot refresh (⌘R) or enable remote debugging (⌘D) from the iOS simulator, while other keyboard inputs work, make sure you are running a debug build configuration. You can check this with:
Product -> Scheme -> Edit Scheme -> Run -> Info -> Build Configuration -> Debug"
I got this tip from here.
Just restart Simulator (close and open the app).

iphone doesn't refresh the localized icon after you change language setting !

I manage to localized app icon and app name for different languages.I found the icon changes depending on the language setting on the iphone only when the first time when you install the app from xcode.
after that, if i change the language setting, the app icon stay the same but only the app name changes to the localized one.
Anyone has an idea is there is way of solving the problem? it seems iphone doens't refresh the icon after you change the language setting.
Tony
I am going through the same problem right now and my conclusion is you are right. There seems to be no way as of now to change the icon on the fly with the language settings.
Have you tried cleaning (Build > Clean or Cmd+Shift+K) before changing the language setting and rebuilding your entire project? I find doing that fixes my app icons all the time. Also, be sure you're changing your iPhone Simulator language settings and not your Mac OS X language settings.