iOS 8.1 Simulator always uses US keyboard layout despite german hardware keyboard

IosXcodeKeyboardIos Simulator

Ios Problem Overview


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?

Ios Solutions


Solution 1 - Ios

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.

Solution 2 - Ios

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

Solution 3 - Ios

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.

Solution 4 - Ios

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

Solution 5 - Ios

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.

Solution 6 - Ios

@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

Solution 7 - Ios

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.

Solution 8 - Ios

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpawiView Question on Stackoverflow
Solution 1 - IosJeremy Huddleston SequoiaView Answer on Stackoverflow
Solution 2 - IosdobihoView Answer on Stackoverflow
Solution 3 - IosmalexView Answer on Stackoverflow
Solution 4 - IosИлья ГоловановView Answer on Stackoverflow
Solution 5 - IosSafeFastExpressiveView Answer on Stackoverflow
Solution 6 - IosmicmdkView Answer on Stackoverflow
Solution 7 - IosUndoView Answer on Stackoverflow
Solution 8 - Iosuser2990765View Answer on Stackoverflow