53
votes

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?

8
I would enable: hardware-> keyboard->Toggle Software Keyboard and change the locale in the soft keyboard, then I can type in my hardware keyboardHorst

8 Answers

36
votes

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

46
votes

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.

14
votes

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
votes

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

7
votes

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
votes

@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
0
votes

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.

0
votes

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");
}