iOS 8.1 Simulator always uses US keyboard layout despite german hardware keyboard
Asked Answered
M

8

54

For some reason, I cannot enter text with my native german keyboard into iOS Simulator any more.

After downloading Xcode 6.1 (which contains iOS 8.1), I was stuck with the US layout.

I tried things like changing all Hardware/Keyboard settings, deleting ~/Library/Preferences/com.apple.iphonesimulator.plist, and resetting the iOS simulator.

Nothing helped!

Should I reinstall the complete package?

Malynda answered 1/10, 2014 at 17:3 Comment(1)
I would enable: hardware-> keyboard->Toggle Software Keyboard and change the locale in the soft keyboard, then I can type in my hardware keyboardEpistasis
M
37

It's iOS 8.1 Simulator's bugs.

I could tested language by setting the "Application Language" in the used scheme.

Go to Product > Scheme > Edit Scheme... or press cmd + Y.

Source: Answer of Yoshihiro Sakamoto in Apple Dev Forum

enter image description here

Metaphor answered 4/1, 2015 at 22:9 Comment(6)
Great! This solved my problem! I explicetely set Application Language to "German" and voila, the simulator accepts my german keyboard!! Thanks a lot!Malynda
Why my "Application Language" part can only choose "English" and "system language" without the country i want to? Even though i have changed simulator language i want to set.Kadiyevka
This help me save a lot of testing time,thanks a lotEgis
How do you find that screen? Can't seem to find it anywhere?Accouchement
I had to both do this and change the simulator system languageBurly
This does not work when setting English as Application Language in Xcode 9.4.1Midiron
N
46

This is a known issue with the iOS 8.1 simulator runtime and is mentioned in the Xcode 6.1 Release Notes:

Localization and Keyboard settings, including 3rd party keyboards, are not correctly honored by Safari, Maps, and developer apps in the iOS 8.1 Simulator. [NSLocale currentLocale] returns en_US and only the English and Emoji keyboards are available. (18418630, 18512161)

The same is true for other preferences that should affect all apps and not just the locale (eg: keyboard settings).

As mentioned in the iOS SDK 8.2 beta 2 Release Notes, this issue should be resolved in iOS 8.2:

Fixed in beta 2 Additional keyboards, including 3rd party keyboards, may not appear in Safari, Maps, or 3rd party apps in iOS Simulator

If you need to use iOS 8.1, you should be able to use the German layout in some apps but not others. For example, Safari and Maps are two examples of apps that it will not work with.

Niagara answered 1/10, 2014 at 21:33 Comment(12)
Sorry, do not understand completely what you mean with: "Please file additional radars if you want to "upvote" the bug with dupes." I do not experience any problems with other programs like Safari or Maps!?Malynda
I am saying that while this is already a known issue, you should file your own radar at bugreport.apple.comNiagara
If this is a known issue, is everybody having this problem? I can't find any complaints regarding this elsewhere!Malynda
Yeah, there are a few other SO threads and reports in devforums.apple.comNiagara
Does this NSLocale issue also lead to [[NSLocale preferredLanguages] objectAtIndex:0] always return "en"? It seems similar to the problem that I'm having, @JeremyHuddlestonSequoia could you do me a favor looking at this? thanks! #26572615Siding
Yes. The root issue is that global preferences aren't working in the 8.1 sim. Keyboard settings and localization are the most visible of such preferences. I'll work to get the release note updated for better clarity.Niagara
The working solution for iOS 8.1 is hereBackbone
why unrelated? The initial question is exactly about inability to enter german text in ios8.1 simulator.Backbone
@Backbone sorry, I was quickly trying to respond to something that I batched up in my head while the site was read-only and made the comment in reply to the wrong thread. My apologies. Please ignore my previous comment.Niagara
Still there in Xcode 6.1.1. It is mentioned in the GM release notes but not on the link you posted.Garvy
@Garvy Yes, the link I posted was for the Xcode release notes front page. It was on it at the time, but that page updates which is why I quoted it. You can still see it by clicking the specific release in the table of contents. I've updated the link.Niagara
@JeremyHuddlestonSequoia: Wow, that was fast. Didn't looked at it. Thanks!Garvy
M
37

It's iOS 8.1 Simulator's bugs.

I could tested language by setting the "Application Language" in the used scheme.

Go to Product > Scheme > Edit Scheme... or press cmd + Y.

Source: Answer of Yoshihiro Sakamoto in Apple Dev Forum

enter image description here

Metaphor answered 4/1, 2015 at 22:9 Comment(6)
Great! This solved my problem! I explicetely set Application Language to "German" and voila, the simulator accepts my german keyboard!! Thanks a lot!Malynda
Why my "Application Language" part can only choose "English" and "system language" without the country i want to? Even though i have changed simulator language i want to set.Kadiyevka
This help me save a lot of testing time,thanks a lotEgis
How do you find that screen? Can't seem to find it anywhere?Accouchement
I had to both do this and change the simulator system languageBurly
This does not work when setting English as Application Language in Xcode 9.4.1Midiron
B
14

Before Apple makes fix one can use the following checked solution based on NSLocale swizzling.

In fact we only need to substitute wrong currentLocale which is broken in iOS8.1 simulator.

Attach the category to projects and add it in .pch file (don't forget to clear and rebuild project).

//  NSLocale+ios8.h
//  Created by Alexey Matveev on 01.11.2014.
//  Copyright (c) 2014 Alexey Matveev. All rights reserved.

#if TARGET_IPHONE_SIMULATOR

// define here your locale identifier: de_DE, ru_RU, etc
#define LOCALE_IDENTIFIER @"de_DE"

@interface NSLocale (iOS8)
@end

#endif

//  NSLocale+ios8.m
//  Created by Alexey Matveev on 01.11.2014.
//  Copyright (c) 2014 Alexey Matveev. All rights reserved.

#if TARGET_IPHONE_SIMULATOR

#import "NSLocale+ios8.h"
#import <objc/runtime.h>

@implementation NSLocale (iOS8)

+ (void)load
{
    Method originalMethod = class_getClassMethod(self, @selector(currentLocale));
    Method swizzledMethod = class_getClassMethod(self, @selector(swizzled_currentLocale));
    method_exchangeImplementations(originalMethod, swizzledMethod);
}

+ (NSLocale*)swizzled_currentLocale
{
    return [NSLocale localeWithLocaleIdentifier:LOCALE_IDENTIFIER];
}

@end

#endif

Hope now you see the same

iOS8 simulator screenshot with German keyboard

One more thing, using this approach you get one pleasent side effect: keyboard chosen via category locale is always in use and doesn't depend on system settings and keyboards added. So simulator setting reset doesn't require to add your keyboard again.

The category approach allows one to override language and region settings for all targets at once without making change of these parameters in each target scheme separately.

Backbone answered 1/11, 2014 at 14:46 Comment(9)
Please clarify. I'm in the USA, and my custom keyboard does not appear, and emoji is always listed even when I delete it. Can this method help me here? (I've tried it as posted and with LOCALE_IDENTIFIER @"en_US" but it has no effect.)Certify
@Jeff, my answer concerns only the default keyboards which guided by system locales.Backbone
Nice, thanks. Worked perfectly for @"ja" (Japanese).Selfdriven
With your code the NSLocale is reported correctly as de_DE. Is there a similar approach to load the correct storyboard from present EN and DE localizations w/out base localization, e.g. categorizing NSBundle?Middling
@konran, sorry, I have no answer.Backbone
Ok, thanks malex. Since nothing existed so far, I tried it, but it's lot more to swizzle in NSBundle to get it working (4 methods and NSUserDefaults languages). I don't know if this is really all, but it looks good as a 1st shot.Middling
@konran, may be you simply need to fix preferredLanguages via swizzling in the same way. I don't know but it could be that main bundle is based on current preferred language.Backbone
@malex, preferredLanguages returns always the correct languages in sequence, e.g. [de, en]. I swizzled pathForResource:ofType:, URLForResource:withExtension: and their derivates working with directories (6 methods in fact) - that does it. Thanks anyway :-)Middling
awsome answer but my default keyboard is emoji when i tap on textfield. i want default keyboard de_DeHeterothallic
C
9

on your target go edit scheme -> select your application lang and application region (german). software keyboard switch layout ok, hardware no )

Confectioner answered 25/10, 2014 at 18:58 Comment(2)
Works for me as well.Deviate
Do you know how to do that from command line? for xcodebuild / xcrun / instruments?Lustig
B
7

There is another known issue with 8.1 that causes keyboards to not display in simulator.

Keyboards Known Issue Additional Keyboards, including 3rd party keyboards, may not appear in Safari, Maps or 3rd party apps on the Simulator.

Workaround: Keyboards should be testable in Calendar, Spotlight, Contacts, and Photos.

I interpret this to mean your enclosing app won't work either. My keyboard won't display in Safari or Maps, but works fine in Photos search bar.

Brenner answered 23/10, 2014 at 20:11 Comment(0)
D
2

@malex' solution by swizzling the currentLocale and adding it to the .pch file almost did the trick for me. It enabled the locale keyboard (danish) but it didn't make it the default keyboard.

To make it the default keyboard I had to swizzle the preferredLanguages method on NSLocale as well.

Thanks @malex.

In all it ended up being:

@interface NSLocale (iOS8)
@end

@implementation NSLocale (iOS8)

+ (void)load
{
    Method originalCurrentLocale = class_getClassMethod(self, @selector(currentLocale));
    Method swizzledCurrentLocale = class_getClassMethod(self, @selector(swizzled_currentLocale));
    method_exchangeImplementations(originalCurrentLocale, swizzledCurrentLocale);

    Method originalPreferredLanguages = class_getClassMethod(self, @selector(preferredLanguages));
    Method swizzledPreferredLanguages = class_getClassMethod(self, @selector(swizzled_preferredLanguages));
    method_exchangeImplementations(originalPreferredLanguages, swizzledPreferredLanguages);
}

+ (NSLocale *)swizzled_currentLocale
{
    return [NSLocale localeWithLocaleIdentifier:@"da_DK"];
}

+ (NSArray *)swizzled_preferredLanguages
{
    return @[@"da"];
}

@end
Distance answered 21/1, 2015 at 10:37 Comment(1)
I got a solution but default keyboard is open smily how can i open directly open da keyboard..Heterothallic
A
1

In the Settings app, under General > Keyboard > Keyboards, tap (click) Add New Keyboard:

enter image description here

If you mean the Simulator won't accept input from your hardware keyboard, you need to connect it (command-shift-K):

enter image description here

This is in the Hardware > Keyboard menu.

Aldenalder answered 1/10, 2014 at 17:10 Comment(2)
Unfortunately, this all didn't help!Malynda
I don't understand why people downvoted this answer without leaving a comment. This was the only thing that helped. The accepted answer doesn't tell what to do when there is no "German" under "Application Language" would upvote 100 times if i could!Merriman
A
0

As an alternative to the fixes mentioned above, one can make use of environment variables as a work around.

Add an environment variable, say "myLocale" under: edit scheme>arguments>environment variables on Xcode.

(Make sure to enable the environment variable whenever you want to force the locale of your liking) enter image description here

In your code, you can add a condition to check if the environment variable is enabled.

NSString *locale = [[[NSProcessInfo processInfo] environment] objectForKey:@"myLocale"];
if (locale) {
    NSLog(@"Using environment variable for locale");
} else{
    NSLog(@"Using locale configured from settings");
}
Alphosis answered 9/3, 2015 at 3:21 Comment(1)
This way you can also avoid the issue that @William-hu reported above like where "Application Language" part can only choose "English" and "system language".Alphosis

© 2022 - 2024 — McMap. All rights reserved.