尽管德国硬件键盘,iOS 8.1 模拟器始终使用美国键盘布局
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26146668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 8.1 Simulator always uses US keyboard layout despite german hardware keyboard
提问by pawi
For some reason, I cannot enter text with my native german keyboard into iOS Simulator any more.
出于某种原因,我无法再使用我的本机德语键盘将文本输入到 iOS 模拟器中。
After downloading Xcode 6.1 (which contains iOS 8.1), I was stuck with the US layout.
下载 Xcode 6.1(包含 iOS 8.1)后,我被困在美国布局。
I tried things like changing all Hardware/Keyboard settings, deleting ~/Library/Preferences/com.apple.iphonesimulator.plist
, and resetting the iOS simulator.
我尝试了更改所有硬件/键盘设置、删除~/Library/Preferences/com.apple.iphonesimulator.plist
和重置 iOS 模拟器等操作。
Nothing helped!
没有任何帮助!
Should I reinstall the complete package?
我应该重新安装完整的软件包吗?
采纳答案by dobiho
It's iOS 8.1 Simulator's bugs.
这是 iOS 8.1 模拟器的错误。
I could tested language by setting the "Application Language" in the used scheme.
我可以通过在使用的方案中设置“应用程序语言”来测试语言。
Go to Product > Scheme > Edit Scheme... or press cmd + Y.
转到产品 > 方案 > 编辑方案...或按 cmd + Y。
Source: Answer of Yoshihiro Sakamoto in Apple Dev Forum
来源:Yoshihiro Sakamoto 在 Apple Dev Forum 的回答
回答by Jeremy Huddleston Sequoia
This is a known issue with the iOS 8.1 simulator runtime and is mentioned in the Xcode 6.1 Release Notes:
这是 iOS 8.1 模拟器运行时的一个已知问题,在Xcode 6.1 发行说明中提到:
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)
iOS 8.1 模拟器中的 Safari、地图和开发者应用程序未正确支持本地化和键盘设置,包括 3rd 方键盘。[NSLocale currentLocale] 返回 en_US 并且只有英文和表情符号键盘可用。(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:
正如iOS SDK 8.2 beta 2 Release Notes 中提到的,这个问题应该在 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
在 beta 2 中修复了其他键盘,包括 3rd 方键盘,可能不会出现在 iOS 模拟器中的 Safari、Maps 或 3rd 方应用程序中
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.
如果您需要使用 iOS 8.1,您应该能够在某些应用程序中使用德语布局,但不能在其他应用程序中使用。例如,Safari 和地图是它无法使用的两个应用程序示例。
回答by malex
Before Apple makes fix one can use the following checked solution based on NSLocale swizzling
.
在 Apple 进行修复之前,可以使用以下基于NSLocale swizzling
.
In fact we only need to substitute wrong currentLocale
which is broken in iOS8.1 simulator.
实际上我们只需要替换currentLocale
iOS8.1模拟器中损坏的错误即可。
Attach the category to projects and add it in .pch
file (don't forget to clear and rebuild project).
将类别附加到项目并将其添加到.pch
文件中(不要忘记清除并重建项目)。
// 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
希望现在你看到同样的
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.
类别方法允许一次性覆盖所有目标的语言和区域设置,而无需分别更改每个目标方案中的这些参数。
回答by Илья Голованов
on your target go edit scheme -> select your application lang and application region (german). software keyboard switch layout ok, hardware no )
在您的目标上编辑方案 -> 选择您的应用程序语言和应用程序区域(德语)。软件键盘开关布局正常,硬件没有)
回答by SafeFastExpressive
There is another known issue with 8.1 that causes keyboards to not display in simulator.
8.1 存在另一个已知问题,该问题导致键盘无法在模拟器中显示。
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.
键盘已知问题 其他键盘(包括 3rd 方键盘)可能不会出现在模拟器上的 Safari、地图或 3rd 方应用程序中。
解决方法:键盘应可在日历、Spotlight、联系人和照片中进行测试。
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.
我将此解释为您的封闭应用程序也无法运行。我的键盘不会在 Safari 或地图中显示,但在照片搜索栏中工作正常。
回答by micmdk
@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.
@malex' 通过混合 currentLocale 并将其添加到 .pch 文件的解决方案几乎对我有用。它启用了语言环境键盘(丹麦语),但并未使其成为默认键盘。
To make it the default keyboard I had to swizzle the preferredLanguages method on NSLocale as well.
为了使它成为默认键盘,我还必须在 NSLocale 上混合使用 preferredLanguages 方法。
Thanks @malex.
谢谢@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
回答by user2990765
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.
添加一个环境变量,在以下位置说“myLocale”:在 Xcode 上编辑方案>参数>环境变量。
(Make sure to enable the environment variable whenever you want to force the locale of your liking)
(每当您想强制使用您喜欢的语言环境时,请确保启用环境变量)
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");
}
回答by Undo
In the Settings app, under General > Keyboard > Keyboards, tap (click) Add New Keyboard:
在“设置”应用中,在“常规”>“键盘”>“键盘”下,点击(单击)添加新键盘:
If you mean the Simulator won't accept input from your hardware keyboard, you need to connect it (command-shift-K):
如果您的意思是模拟器不接受来自硬件键盘的输入,则需要连接它(command-shift-K):
This is in the Hardware > Keyboard menu.
这是在硬件 > 键盘菜单中。