iOS - 在 App 内优雅的切换语言
手动前往 Github 项目地址 ,下载完成后拷贝 Localized
目录到工程中
Podfile
文件导入 pod 'CCLocalizedLanguage'
[LanguageManager switchLanguage:selectedLanguage];
[LanguageManager resetToSystemLanguage];
NSArray *array = UIApplication.sharedApplication.connectedScenes.allObjects;
UIWindowScene *windowScene = array.firstObject;
UIWindow *window = windowScene.windows.firstObject;
UINavigationController *rootVC = (UINavigationController *)window.rootViewController;
UIViewController *newVC = [rootVC.viewControllers.firstObject.class.alloc init];
UINavigationController *newRootVC = [[UINavigationController alloc] initWithRootViewController:newVC];
SwitchLanguageVC *languageVC = [[SwitchLanguageVC alloc] init];
[newRootVC pushViewController:languageVC animated:NO];
window.rootViewController = newRootVC;
rootVC = nil;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[newRootVC popViewControllerAnimated:YES];
});