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?

pkamb
  • 33,281
  • 23
  • 160
  • 191
pawi
  • 2,463
  • 3
  • 16
  • 16
  • 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 '14 at 05:03

8 Answers8

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.

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
  • 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 03 '14 at 08:56
  • I am saying that while this is already a known issue, you should file your own radar at http://bugreport.apple.com – Jeremy Huddleston Sequoia Oct 03 '14 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 05 '14 at 08:55
  • Yeah, there are a few other SO threads and reports in devforums.apple.com – Jeremy Huddleston Sequoia Oct 24 '14 at 14:12
  • 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! http://stackoverflow.com/questions/26572115/nslocale-preferredlanguages-objectatindex0-always-return-en – S1U Oct 27 '14 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. – Jeremy Huddleston Sequoia Oct 30 '14 at 02:12
  • The working solution for iOS 8.1 is [here](http://stackoverflow.com/a/26690370/2066428) – malex Nov 01 '14 at 14:56
  • why unrelated? The initial question is exactly about inability to enter german text in ios8.1 simulator. – malex Nov 02 '14 at 13:03
  • @malex 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. – Jeremy Huddleston Sequoia Nov 03 '14 at 08:56
  • Still there in Xcode 6.1.1. It is mentioned in the GM release notes but not on the link you posted. – testing Dec 04 '14 at 08:25
  • @testing 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. – Jeremy Huddleston Sequoia Dec 04 '14 at 08:27
  • @JeremyHuddlestonSequoia: Wow, that was fast. Didn't looked at it. Thanks! – testing Dec 04 '14 at 08:29
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

user2007844
  • 3
  • 1
  • 2
dobiho
  • 1,025
  • 1
  • 11
  • 22
  • 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 '15 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 04 '15 at 09:26
  • This help me save a lot of testing time,thanks a lot – Will Mar 04 '15 at 04:59
  • 1
    How do you find that screen? Can't seem to find it anywhere? – Kevin Simper Apr 17 '15 at 10:01
  • I had to both do this and change the simulator system language – Dulgan Jun 11 '15 at 08:56
  • This does not work when setting English as Application Language in Xcode 9.4.1 – Julius Aug 31 '18 at 14:33
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.

malex
  • 9,874
  • 3
  • 56
  • 77
  • 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 '14 at 23:53
  • @Jeff, my answer concerns only the default keyboards which guided by system locales. – malex Nov 15 '14 at 22:25
  • Nice, thanks. Worked perfectly for @"ja" (Japanese). – Kalle Nov 30 '14 at 03: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 09 '15 at 00:57
  • @konran, sorry, I have no answer. – malex Jan 09 '15 at 01:09
  • 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. – konran Jan 09 '15 at 15:21
  • @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. – malex Feb 17 '15 at 17:43
  • @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 :-) – konran Feb 17 '15 at 20:04
  • awsome answer but my default keyboard is emoji when i tap on textfield. i want default keyboard de_De – Maulik shah Jun 08 '20 at 17:30
9

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

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.

SafeFastExpressive
  • 3,637
  • 2
  • 32
  • 39
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
micmdk
  • 951
  • 1
  • 8
  • 12
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.

Undo
  • 25,519
  • 37
  • 106
  • 129
  • 3
    Unfortunately, this all didn't help! – pawi Oct 02 '14 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 05 '16 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");
}
user2990765
  • 387
  • 2
  • 3
  • 16
  • 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". – user2990765 Apr 16 '15 at 21:39