这就是:我有一个按钮,用于更改我的应用程序的当前语言。这很有效,但是,我的社交按钮(例如Google和Facebook)不会改变语言(GIDSignInButton, FBSDKLoginButton
)。我猜他们在AppDelegate上获得了我设备的当前语言,但是,我不想在重新设置应用程序或应用程序代表时搞砸。
有什么建议吗?我可以以编程方式重新启动facebook系统以便再次使用该语言吗?
这是我的setLanguage方法:
+ (void)setLanguage:(NSString *)language
{
//if language not supported we default to spanish
if (language == nil || ![SMLocalizedString isLanguageSupported:language]){
//defaults to spanish
language = @"es";
}
//Sotres new language setting in user preferences
[SMLocalizedString updateCurrentLanguage:language];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
object_setClass([NSBundle mainBundle], [BundleEx class]);
});
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:language, nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
id value = language ? [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]] : nil;
objc_setAssociatedObject([NSBundle mainBundle], &kBundleKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}