有没有办法使无效的NSBundle本地化caching,重新启动应用程序?
让我们假设我们可以改变运行时Localizable.strings,这是放置在NSBundle在当前,即使我们改变它的内容, NSLocalizedString会返回旧的(caching)的值。
- 运行应用程序
- 为特定的key1 < – value1获取LocalizableString
- 更改Localizable.strings key1 = value2
- < – 在应用程序中执行某些操作来使本地化caching失效 – >
- 检查特定key1 == value2的LocalizableString
我已经尝试过了:
- [[NSBundble mainBundle] invalidateResourceCache]
- [UIApplication _performMemoryWarning]
- 试着看,如果有一些字典。 用于caching,在NSBundle的ivars中。
- 试图看到,在GNUStep实施NSBundle,但它不同于我们在iOS 6.0
我无法做到(按照定义): – 我不能swizzle [NSBundle localizableStringForKey:值:表] – 我不能改变macros – 一般来说,我不能影响任何原始项目代码,只有在第4步添加的东西
这仅用于开发目的。 所以,我不需要在AppStore中发布它,所以任何私有方法或解决scheme都可以。
所以,问题是。 可能是有人知道这样做的方式,或者有人给我另一个想法如何做到这一点? 谢谢。
注:此解决scheme使用私有API,如果您使用此代码,则向App Store提交的应用程序将被拒绝。
所以,经过一些search,我find了帮助我的链接
如何删除NSBundlecaching
// First, we declare the function. Making it weak-linked // ensures the preference pane won't crash if the function // is removed from in a future version of Mac OS X. extern void _CFBundleFlushBundleCaches(CFBundleRef bundle) __attribute__((weak_import)); BOOL FlushBundleCache(NSBundle *prefBundle) { // Before calling the function, we need to check if it exists // since it was weak-linked. if (_CFBundleFlushBundleCaches != NULL) { NSLog(@"Flushing bundle cache with _CFBundleFlushBundleCaches"); CFBundleRef cfBundle = CFBundleCreate(nil, (CFURLRef)[prefBundle bundleURL]); _CFBundleFlushBundleCaches(cfBundle); CFRelease(cfBundle); return YES; // Success } return NO; // Not available }
在刷新捆绑caching之后,使用新的本地化密钥。 所以现在我不需要在模拟器中重新启动我的应用程序,以查看可本地化的string的变化。