Reputation: 2124
I have a scenario in which I have localization files to be downloaded from server. I download the file at start of application and store it in folder in bundle. Like if its English file I store it in bundle under folder 'en.lproj' with name Localizable.strings.
Now when file is downloaded, I load the bundle using bundleWithPath: method. Once it is loaded I show localization using method
NSLocalizedStringFromTableInBundle(key, @"Localizable", bundle, @"");
Till here it works fine. Now if the file is updated from server I again download the English file and I replace the old file with new one. But the application shows the localization from old file which was replaced. Can anyone please tell me if we can reload the bundle again so that the updates are reflected.
In the above scenario the application is not killed when file is updated. If I kill the application and restart it then the changes are reflected. But I want the changes to be reflected without killing the application.
Is there any method to unload the loaded NSBundle?
Upvotes: 4
Views: 889
Reputation: 2124
Got the answer..
This code helped. This is used to flush the loaded bundle from cache.
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
}
Upvotes: 4