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?

1
  • 1
    I would enable: hardware-> keyboard->Toggle Software Keyboard and change the locale in the soft keyboard, then I can type in my hardware keyboard
    – Horst
    Dec 12, 2014 at 5:03

8 Answers 8

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.

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!?
    – pawi
    Oct 3, 2014 at 8:56
  • I am saying that while this is already a known issue, you should file your own radar at bugreport.apple.com Oct 3, 2014 at 10:02
  • If this is a known issue, is everybody having this problem? I can't find any complaints regarding this elsewhere!
    – pawi
    Oct 5, 2014 at 8:55
  • 2
    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! stackoverflow.com/questions/26572115/…
    – S1U
    Oct 27, 2014 at 22:13
  • 1
    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. Oct 30, 2014 at 2:12
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

6
  • Great! This solved my problem! I explicetely set Application Language to "German" and voila, the simulator accepts my german keyboard!! Thanks a lot!
    – pawi
    Jan 17, 2015 at 19:01
  • 9
    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.
    – William Hu
    Feb 4, 2015 at 9:26
  • This help me save a lot of testing time,thanks a lot
    – Will
    Mar 4, 2015 at 4:59
  • 1
    How do you find that screen? Can't seem to find it anywhere? Apr 17, 2015 at 10:01
  • I had to both do this and change the simulator system language
    – Dulgan
    Jun 11, 2015 at 8:56
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.

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.)
    – Jeff
    Nov 13, 2014 at 23:53
  • @Jeff, my answer concerns only the default keyboards which guided by system locales.
    – malex
    Nov 15, 2014 at 22:25
  • Nice, thanks. Worked perfectly for @"ja" (Japanese).
    – Kalle
    Nov 30, 2014 at 3:40
  • 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?
    – konran
    Jan 9, 2015 at 0:57
  • @konran, sorry, I have no answer.
    – malex
    Jan 9, 2015 at 1:09
9

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

2
  • Works for me as well. Dec 2, 2014 at 15:58
  • Do you know how to do that from command line? for xcodebuild / xcrun / instruments?
    – Ron D.
    Jan 19, 2015 at 9:33
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.

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
1
  • I got a solution but default keyboard is open smily how can i open directly open da keyboard.. Jun 8, 2020 at 17:02
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.

2
  • 3
    Unfortunately, this all didn't help!
    – pawi
    Oct 2, 2014 at 10:20
  • 1
    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!
    – ParkerHalo
    Feb 5, 2016 at 11:50
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");
}
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". Apr 16, 2015 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.